diff --git a/musikr/src/main/jni/src/lib.rs b/musikr/src/main/jni/src/lib.rs index 56312e061..18067a370 100644 --- a/musikr/src/main/jni/src/lib.rs +++ b/musikr/src/main/jni/src/lib.rs @@ -8,7 +8,6 @@ mod taglib; mod jstream; use taglib::file::FileRef; - use jstream::JInputStream; type SharedEnv<'local> = Rc>>; @@ -23,40 +22,34 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>( let shared_env = Rc::new(RefCell::new(env)); let mut stream = JInputStream::new(shared_env.clone(), input); let file_ref = FileRef::new(stream); - // file_ref.file().and_then(|file| { - // let audio_properties = file.audio_properties().map(|props| AudioProperties { - // length_in_milliseconds: props.length_in_milliseconds(), - // bitrate_in_kilobits_per_second: props.bitrate(), - // sample_rate_in_hz: props.sample_rate(), - // number_of_channels: props.channels(), - // }); + let title = file_ref.file().and_then(|file| { + let audio_properties = file.audio_properties(); - // if let Some(vorbis_file) = file.as_vorbis() { - // let xiph_comments = vorbis_file - // .xiph_comments() - // .map(|comments| comments.field_list_map().to_hashmap()); - - // } else if let Some(opus_file) = file.as_opus() { - // let xiph_comments = opus_file - // .xiph_comments() - // .map(|comments| comments.field_list_map().to_hashmap()); - - // Some(File::Opus { - // audio_properties, - // xiph_comments, - // }) - // } else if let Some(flac_file) = file.as_flac() { - // let xiph_comments = flac_file - // .xiph_comments() - // .map(|comments| comments.field_list_map().to_hashmap()); - // Some(File::FLAC { - // audio_properties, - // xiph_comments, - // }) - // } else { - // Some(File::Unknown { audio_properties }) - // } - // }); + if let Some(vorbis_file) = file.as_vorbis() { + vorbis_file + .xiph_comments() + .map(|comments| comments.field_list_map().to_hashmap()) + .and_then(|comments| comments.get("TITLE").cloned()) + .and_then(|title| title.first().cloned()) + .map(|s| s.to_string()) + } else if let Some(opus_file) = file.as_opus() { + opus_file + .xiph_comments() + .map(|comments| comments.field_list_map().to_hashmap()) + .and_then(|comments| comments.get("TITLE").cloned()) + .and_then(|title| title.first().cloned()) + .map(|s| s.to_string()) + } else if let Some(flac_file) = file.as_flac() { + flac_file + .xiph_comments() + .map(|comments| comments.field_list_map().to_hashmap()) + .and_then(|comments| comments.get("TITLE").cloned()) + .and_then(|title| title.first().cloned()) + .map(|s| s.to_string()) + } else { + None + } + }); // Return the title let output = shared_env.borrow_mut().new_string("title").expect("Couldn't create string!"); diff --git a/musikr/src/main/jni/src/taglib/iostream.rs b/musikr/src/main/jni/src/taglib/iostream.rs index d1daf0093..1d220199d 100644 --- a/musikr/src/main/jni/src/taglib/iostream.rs +++ b/musikr/src/main/jni/src/taglib/iostream.rs @@ -44,9 +44,6 @@ impl<'a> Drop for BridgedIOStream<'a> { pub(super) struct DynIOStream<'a>(Box); impl<'a> DynIOStream<'a> { - pub fn new(stream: T) -> Self { - DynIOStream(Box::new(stream)) - } // Implement the exposed functions for cxx bridge pub fn name(&mut self) -> String {