Implement AudioFile for TaggedFile

This commit is contained in:
Serial 2022-04-03 17:18:11 -04:00
parent 7455f08b41
commit 20e1ecf62d
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
3 changed files with 28 additions and 6 deletions

View file

@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **ID3v2**: `FrameValue::Popularimeter`
- `ItemValue::{into_string, into_binary}`
- `Tag::take_strings`
- `TaggedFile` now implements `AudioFile`
### Changed
- **MP4**: Sample rates and channels are now retrieved from the [audio specific config](https://wiki.multimedia.cx/index.php?title=MPEG-4_Audio#Audio_Specific_Config) (if possible).

View file

@ -1,4 +1,4 @@
use lofty::{Accessor, Probe};
use lofty::{Accessor, AudioFile, Probe};
use std::path::Path;
fn main() {

View file

@ -51,11 +51,6 @@ impl TaggedFile {
self.ty
}
/// Returns the file's [`FileProperties`]
pub fn properties(&self) -> &FileProperties {
&self.properties
}
/// Returns all tags
pub fn tags(&self) -> &[Tag] {
self.tags.as_slice()
@ -177,6 +172,32 @@ impl TaggedFile {
}
}
impl AudioFile for TaggedFile {
type Properties = FileProperties;
fn read_from<R>(reader: &mut R, read_properties: bool) -> Result<Self>
where
R: Read + Seek,
Self: Sized,
{
crate::probe::Probe::new(reader)
.guess_file_type()?
.read(read_properties)
}
fn properties(&self) -> &Self::Properties {
&self.properties
}
fn contains_tag(&self) -> bool {
!self.tags.is_empty()
}
fn contains_tag_type(&self, tag_type: TagType) -> bool {
self.tags.iter().any(|t| t.tag_type() == tag_type)
}
}
#[derive(PartialEq, Copy, Clone, Debug)]
#[allow(missing_docs)]
#[non_exhaustive]