Albums

Overview

Sounds supports the concept of Albums which are, as you would expect, a collection of Tracks which can be played in order.
The Album uses the OSs Media Player (Shade) to display the tracks as they are played.
A user can use the skip back, forward and pause buttons to navigate the album.

Playing an Album

If you want to play a collection of tracks then you can create an Album with a static set of Tracks or a virtual set of Tracks.

Play album with static set of Tracks

1
var album = Album.fromTracks([
2
Track.fromFile('sample.acc'),
3
Track.fromURL('http://fqdn/sample.mp3'),
4
]);
5
player.onStopped = ({wasUser}) => player.release();
6
album.play();
Copied!
By default an Ablum displays the OSs' audio UI (Shade). You can suppress the UI via by passing in SoundPlayer.noUI() to the Album in which case the Tracks will be played sequentially until they complete. (I'm not certain this is actually useful).
1
var album = Album.fromTracks([
2
Track.fromFile('sample.acc'),
3
Track.fromURL('http://fqdn/sample.mp3'),
4
]
5
, session: SoundPlayer.noUI());
6
player.onStopped = ({wasUser}) => player.release();
7
album.play();
Copied!

Play album with a virtual set of Tracks

Virtual tracks allow you to create an album of infinite size which could be useful if you are pulling audio from an external source.
If you create a virtual album you MUST implement the onSkipForward , onSkipBackwards and onFirstTrack methods to supply the album with Tracks on demand.
1
var album = Album.virtual();
2
album.onFirstTrack = (int currentTrackIndex, Track current)
3
=> Track('http://random/xxxx');
4
album.onSkipForward = (int currentTrackIndex, Track current)
5
=> Track('http://random/xxxx');
6
album.onSkipBackwards = (int currentTrackIndex, Track current)
7
=> Track('http://random/xxxx');
8
player.onStopped = ({wasUser}) => player.release();
9
album.play();
Copied!

Controlling Playback

The SoundPlayer provides fined grained control over how the audio is played as well as been able to monitor playback and respond to user events.
Importantly SoundPlayer also allows you to play multiple audio files using the same session.
Maintaining the same session is important if you are using the OSs' audio UI for user control. If you don't use a single SoundPlayer then the user will experience flicker between tracks as the OSs' audio player is destroyed and recreated between each track.
The Album class provides an easy to use method of utilising a single session without the complications of an SoundPlayer.
1
var player = SoundPlayer.withShadeUI();
2
​
3
var track = Track.fromFile('sample.aac');
4
track.title = 'Corona Virus Rock';
5
player.onStarted => print('started');
6
player.onStopped = ({wasUser}) => print('stopped');
7
player.onPause => print('paused');
8
player.onResume => print('resumed');
9
player.play(track);
10
​
11
...
12
​
13
player.release();
Copied!
Last modified 7mo ago