Struct AudioProperties

Source
pub struct AudioProperties<'a> { /* private fields */ }
Expand description

Common audio file properties.

Instances of AudioProperties can only be created through the taglib::File::audioproperties() method.

Implementations§

Source§

impl<'a> AudioProperties<'a>

Source

pub fn length(&self) -> u32

Returns the length, in seconds, of the track.

Examples found in repository?
examples/tagreader.rs (line 38)
5pub fn main() {
6    let args: Vec<String> = env::args().collect();
7
8    for i in 1..args.len() {
9        let ref arg = args[i];
10        let file = match taglib::File::new(arg) {
11            Ok(f) => f,
12            Err(e) => {
13                println!("Invalid file {} (error: {:?})", arg, e);
14                continue;
15            }
16        };
17
18        println!("*** \"{}\" ***", arg);
19
20        match file.tag() {
21            Ok(t) => {
22                println!("-- TAG --");
23                println!("title   - {}", t.title().unwrap_or_default());
24                println!("artist  - {}", t.artist().unwrap_or_default());
25                println!("album   - {}", t.album().unwrap_or_default());
26                println!("year    - {}", t.year().unwrap_or_default());
27                println!("comment - {}", t.comment().unwrap_or_default());
28                println!("track   - {}", t.track().unwrap_or_default());
29                println!("genre   - {}", t.genre().unwrap_or_default());
30            }
31            Err(e) => {
32                println!("No available tags for {} (error: {:?})", arg, e);
33            }
34        }
35
36        match file.audioproperties() {
37            Ok(p) => {
38                let secs = p.length() % 60;
39                let mins = (p.length() - secs) / 60;
40
41                println!("-- AUDIO --");
42                println!("bitrate     - {}", p.bitrate());
43                println!("sample rate - {}", p.samplerate());
44                println!("channels    - {}", p.channels());
45                println!("length      - {}m:{}s", mins, secs);
46            }
47            Err(e) => {
48                println!("No available audio properties for {} (error: {:?})", arg, e);
49            }
50        }
51    }
52}
Source

pub fn bitrate(&self) -> u32

Returns the most appropriate bit rate for the track, in kB/s. For constant bit rate formats, the returned value is the bit rate of the file; for variable bit rate formats this is either the average or the nominal bit rate.

Examples found in repository?
examples/tagreader.rs (line 42)
5pub fn main() {
6    let args: Vec<String> = env::args().collect();
7
8    for i in 1..args.len() {
9        let ref arg = args[i];
10        let file = match taglib::File::new(arg) {
11            Ok(f) => f,
12            Err(e) => {
13                println!("Invalid file {} (error: {:?})", arg, e);
14                continue;
15            }
16        };
17
18        println!("*** \"{}\" ***", arg);
19
20        match file.tag() {
21            Ok(t) => {
22                println!("-- TAG --");
23                println!("title   - {}", t.title().unwrap_or_default());
24                println!("artist  - {}", t.artist().unwrap_or_default());
25                println!("album   - {}", t.album().unwrap_or_default());
26                println!("year    - {}", t.year().unwrap_or_default());
27                println!("comment - {}", t.comment().unwrap_or_default());
28                println!("track   - {}", t.track().unwrap_or_default());
29                println!("genre   - {}", t.genre().unwrap_or_default());
30            }
31            Err(e) => {
32                println!("No available tags for {} (error: {:?})", arg, e);
33            }
34        }
35
36        match file.audioproperties() {
37            Ok(p) => {
38                let secs = p.length() % 60;
39                let mins = (p.length() - secs) / 60;
40
41                println!("-- AUDIO --");
42                println!("bitrate     - {}", p.bitrate());
43                println!("sample rate - {}", p.samplerate());
44                println!("channels    - {}", p.channels());
45                println!("length      - {}m:{}s", mins, secs);
46            }
47            Err(e) => {
48                println!("No available audio properties for {} (error: {:?})", arg, e);
49            }
50        }
51    }
52}
Source

pub fn samplerate(&self) -> u32

Returns the sample rate, in Hz.

Examples found in repository?
examples/tagreader.rs (line 43)
5pub fn main() {
6    let args: Vec<String> = env::args().collect();
7
8    for i in 1..args.len() {
9        let ref arg = args[i];
10        let file = match taglib::File::new(arg) {
11            Ok(f) => f,
12            Err(e) => {
13                println!("Invalid file {} (error: {:?})", arg, e);
14                continue;
15            }
16        };
17
18        println!("*** \"{}\" ***", arg);
19
20        match file.tag() {
21            Ok(t) => {
22                println!("-- TAG --");
23                println!("title   - {}", t.title().unwrap_or_default());
24                println!("artist  - {}", t.artist().unwrap_or_default());
25                println!("album   - {}", t.album().unwrap_or_default());
26                println!("year    - {}", t.year().unwrap_or_default());
27                println!("comment - {}", t.comment().unwrap_or_default());
28                println!("track   - {}", t.track().unwrap_or_default());
29                println!("genre   - {}", t.genre().unwrap_or_default());
30            }
31            Err(e) => {
32                println!("No available tags for {} (error: {:?})", arg, e);
33            }
34        }
35
36        match file.audioproperties() {
37            Ok(p) => {
38                let secs = p.length() % 60;
39                let mins = (p.length() - secs) / 60;
40
41                println!("-- AUDIO --");
42                println!("bitrate     - {}", p.bitrate());
43                println!("sample rate - {}", p.samplerate());
44                println!("channels    - {}", p.channels());
45                println!("length      - {}m:{}s", mins, secs);
46            }
47            Err(e) => {
48                println!("No available audio properties for {} (error: {:?})", arg, e);
49            }
50        }
51    }
52}
Source

pub fn channels(&self) -> u32

Returns the number of audio channels.

Examples found in repository?
examples/tagreader.rs (line 44)
5pub fn main() {
6    let args: Vec<String> = env::args().collect();
7
8    for i in 1..args.len() {
9        let ref arg = args[i];
10        let file = match taglib::File::new(arg) {
11            Ok(f) => f,
12            Err(e) => {
13                println!("Invalid file {} (error: {:?})", arg, e);
14                continue;
15            }
16        };
17
18        println!("*** \"{}\" ***", arg);
19
20        match file.tag() {
21            Ok(t) => {
22                println!("-- TAG --");
23                println!("title   - {}", t.title().unwrap_or_default());
24                println!("artist  - {}", t.artist().unwrap_or_default());
25                println!("album   - {}", t.album().unwrap_or_default());
26                println!("year    - {}", t.year().unwrap_or_default());
27                println!("comment - {}", t.comment().unwrap_or_default());
28                println!("track   - {}", t.track().unwrap_or_default());
29                println!("genre   - {}", t.genre().unwrap_or_default());
30            }
31            Err(e) => {
32                println!("No available tags for {} (error: {:?})", arg, e);
33            }
34        }
35
36        match file.audioproperties() {
37            Ok(p) => {
38                let secs = p.length() % 60;
39                let mins = (p.length() - secs) / 60;
40
41                println!("-- AUDIO --");
42                println!("bitrate     - {}", p.bitrate());
43                println!("sample rate - {}", p.samplerate());
44                println!("channels    - {}", p.channels());
45                println!("length      - {}m:{}s", mins, secs);
46            }
47            Err(e) => {
48                println!("No available audio properties for {} (error: {:?})", arg, e);
49            }
50        }
51    }
52}

Auto Trait Implementations§

§

impl<'a> Freeze for AudioProperties<'a>

§

impl<'a> RefUnwindSafe for AudioProperties<'a>

§

impl<'a> !Send for AudioProperties<'a>

§

impl<'a> !Sync for AudioProperties<'a>

§

impl<'a> Unpin for AudioProperties<'a>

§

impl<'a> UnwindSafe for AudioProperties<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.