mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
Implement AudioFile
for TaggedFile
This commit is contained in:
parent
7455f08b41
commit
20e1ecf62d
3 changed files with 28 additions and 6 deletions
|
@ -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).
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lofty::{Accessor, Probe};
|
||||
use lofty::{Accessor, AudioFile, Probe};
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
|
|
31
src/file.rs
31
src/file.rs
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue