Commit 4530e457 authored by Viktor Lidholt's avatar Viktor Lidholt

Unifies interfaces for SoundTrackPlayer and SoundEffectPlayer

parent a750da56
...@@ -21,7 +21,6 @@ class SoundEffect { ...@@ -21,7 +21,6 @@ class SoundEffect {
class SoundEffectStream { class SoundEffectStream {
SoundEffectStream( SoundEffectStream(
this.sound, this.sound,
this.tag,
this.loop, this.loop,
this.volume, this.volume,
this.pitch, this.pitch,
...@@ -36,7 +35,6 @@ class SoundEffectStream { ...@@ -36,7 +35,6 @@ class SoundEffectStream {
double volume = 1.0; double volume = 1.0;
double pitch = 1.0; double pitch = 1.0;
double pan = 0.0; double pan = 0.0;
Object tag;
// TODO: Implement completion callback. On completion, sounds should // TODO: Implement completion callback. On completion, sounds should
// also be removed from the list of playing sounds. // also be removed from the list of playing sounds.
...@@ -62,7 +60,7 @@ class SoundEffectPlayer { ...@@ -62,7 +60,7 @@ class SoundEffectPlayer {
} }
MediaServiceProxy _mediaService; MediaServiceProxy _mediaService;
List<SoundEffectStream> _playingSounds = []; List<SoundEffectStream> _soundEffectStreams = [];
// TODO: This should no longer be needed when moving to SoundPool backing // TODO: This should no longer be needed when moving to SoundPool backing
Map<SoundEffect,MediaPlayerProxy> _mediaPlayers = {}; Map<SoundEffect,MediaPlayerProxy> _mediaPlayers = {};
...@@ -87,8 +85,7 @@ class SoundEffectPlayer { ...@@ -87,8 +85,7 @@ class SoundEffectPlayer {
SoundEffectStream play( SoundEffectStream play(
SoundEffect sound, SoundEffect sound,
[Object tag, [bool loop = false,
bool loop = false,
double volume = 1.0, double volume = 1.0,
double pitch = 1.0, double pitch = 1.0,
double pan = 0.0, double pan = 0.0,
...@@ -97,7 +94,6 @@ class SoundEffectPlayer { ...@@ -97,7 +94,6 @@ class SoundEffectPlayer {
// Create new PlayingSound object // Create new PlayingSound object
SoundEffectStream playingSound = new SoundEffectStream( SoundEffectStream playingSound = new SoundEffectStream(
sound, sound,
tag,
loop, loop,
volume, volume,
pitch, pitch,
...@@ -117,7 +113,7 @@ class SoundEffectPlayer { ...@@ -117,7 +113,7 @@ class SoundEffectPlayer {
playingSound._player.ptr.start(); playingSound._player.ptr.start();
}); });
_playingSounds.add(playingSound); _soundEffectStreams.add(playingSound);
_mediaPlayers[sound] = playingSound._player; _mediaPlayers[sound] = playingSound._player;
} else { } else {
// Reuse player // Reuse player
...@@ -129,31 +125,16 @@ class SoundEffectPlayer { ...@@ -129,31 +125,16 @@ class SoundEffectPlayer {
return playingSound; return playingSound;
} }
void stop(Object tag) { void stop(SoundEffectStream stream) {
for (int i = _playingSounds.length; i >= 0; i--) { stream._player.ptr.pause();
SoundEffectStream playingSound = _playingSounds[i]; _soundEffectStreams.remove(stream);
if (playingSound.tag == tag) {
playingSound._player.ptr.pause();
_playingSounds.removeAt(i);
}
}
}
List<SoundEffectStream> playingSoundsForTag(Object tag) {
List<SoundEffectStream> list = [];
for (SoundEffectStream playingSound in _playingSounds) {
if (playingSound.tag == tag) {
list.add(playingSound);
}
}
return list;
} }
void stopAll() { void stopAll() {
for (SoundEffectStream playingSound in _playingSounds) { for (SoundEffectStream playingSound in _soundEffectStreams) {
playingSound._player.ptr.pause(); playingSound._player.ptr.pause();
} }
_playingSounds = []; _soundEffectStreams = [];
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment