mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
+42
@@ -0,0 +1,42 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.media.SoundTransform;
|
||||
import org.osmf.traits.AudioTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioAudioTrait extends AudioTrait
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioAudioTrait(soundAdapter:SoundAdapter)
|
||||
{
|
||||
super();
|
||||
this.soundAdapter = soundAdapter;
|
||||
soundAdapter.soundTransform.volume = volume;
|
||||
soundAdapter.soundTransform.pan = pan;
|
||||
}
|
||||
|
||||
override protected function volumeChangeStart(newVolume:Number) : void
|
||||
{
|
||||
var soundTransform:SoundTransform = this.soundAdapter.soundTransform;
|
||||
soundTransform.volume = muted ? 0 : newVolume;
|
||||
this.soundAdapter.soundTransform = soundTransform;
|
||||
}
|
||||
|
||||
override protected function mutedChangeStart(newMuted:Boolean) : void
|
||||
{
|
||||
var soundTransform:SoundTransform = this.soundAdapter.soundTransform;
|
||||
soundTransform.volume = newMuted ? 0 : volume;
|
||||
this.soundAdapter.soundTransform = soundTransform;
|
||||
}
|
||||
|
||||
override protected function panChangeStart(newPan:Number) : void
|
||||
{
|
||||
var soundTransform:SoundTransform = this.soundAdapter.soundTransform;
|
||||
soundTransform.pan = newPan;
|
||||
this.soundAdapter.soundTransform = soundTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.traits.PlayState;
|
||||
import org.osmf.traits.PlayTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioPlayTrait extends PlayTrait
|
||||
{
|
||||
|
||||
private var lastPlayFailed:Boolean = false;
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioPlayTrait(soundAdapter:SoundAdapter)
|
||||
{
|
||||
super();
|
||||
this.soundAdapter = soundAdapter;
|
||||
soundAdapter.addEventListener(Event.COMPLETE,this.onPlaybackComplete,false,1,true);
|
||||
}
|
||||
|
||||
override protected function playStateChangeStart(newPlayState:String) : void
|
||||
{
|
||||
if(newPlayState == PlayState.PLAYING)
|
||||
{
|
||||
this.lastPlayFailed = !this.soundAdapter.play();
|
||||
}
|
||||
else if(newPlayState == PlayState.PAUSED)
|
||||
{
|
||||
this.soundAdapter.pause();
|
||||
}
|
||||
else if(newPlayState == PlayState.STOPPED)
|
||||
{
|
||||
this.soundAdapter.stop();
|
||||
}
|
||||
}
|
||||
|
||||
override protected function playStateChangeEnd() : void
|
||||
{
|
||||
if(this.lastPlayFailed)
|
||||
{
|
||||
stop();
|
||||
this.lastPlayFailed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
super.playStateChangeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private function onPlaybackComplete(event:Event) : void
|
||||
{
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import org.osmf.traits.SeekTrait;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioSeekTrait extends SeekTrait
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioSeekTrait(timeTrait:TimeTrait, soundAdapter:SoundAdapter)
|
||||
{
|
||||
super(timeTrait);
|
||||
this.soundAdapter = soundAdapter;
|
||||
}
|
||||
|
||||
override protected function seekingChangeStart(newSeeking:Boolean, time:Number) : void
|
||||
{
|
||||
if(newSeeking)
|
||||
{
|
||||
this.soundAdapter.seek(time);
|
||||
}
|
||||
}
|
||||
|
||||
override protected function seekingChangeEnd(time:Number) : void
|
||||
{
|
||||
super.seekingChangeEnd(time);
|
||||
if(seeking == true)
|
||||
{
|
||||
setSeeking(false,time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioTimeTrait extends TimeTrait
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioTimeTrait(soundAdapter:SoundAdapter)
|
||||
{
|
||||
super();
|
||||
this.soundAdapter = soundAdapter;
|
||||
soundAdapter.addEventListener(ProgressEvent.PROGRESS,this.onDownloadProgress,false,0,true);
|
||||
soundAdapter.addEventListener(SoundAdapter.DOWNLOAD_COMPLETE,this.onDownloadComplete,false,0,true);
|
||||
soundAdapter.addEventListener(Event.COMPLETE,this.onPlaybackComplete,false,0,true);
|
||||
}
|
||||
|
||||
override public function get currentTime() : Number
|
||||
{
|
||||
return this.soundAdapter.currentTime;
|
||||
}
|
||||
|
||||
private function onDownloadProgress(event:Event) : void
|
||||
{
|
||||
if(!isNaN(this.soundAdapter.estimatedDuration) && this.soundAdapter.estimatedDuration > 0)
|
||||
{
|
||||
this.soundAdapter.removeEventListener(ProgressEvent.PROGRESS,this.onDownloadProgress);
|
||||
setDuration(this.soundAdapter.estimatedDuration);
|
||||
}
|
||||
}
|
||||
|
||||
private function onDownloadComplete(event:Event) : void
|
||||
{
|
||||
setDuration(this.soundAdapter.estimatedDuration);
|
||||
}
|
||||
|
||||
private function onPlaybackComplete(event:Event) : void
|
||||
{
|
||||
signalComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
|
||||
[Event(name="progress",type="flash.events.ProgressEvent")]
|
||||
[Event(name="downloadComplete",type="flash.events.Event")]
|
||||
[Event(name="complete",type="flash.events.Event")]
|
||||
[ExcludeClass]
|
||||
public class SoundAdapter extends EventDispatcher
|
||||
{
|
||||
|
||||
public static const DOWNLOAD_COMPLETE:String = "downloadComplete";
|
||||
|
||||
private var owner:MediaElement;
|
||||
|
||||
private var _soundTransform:SoundTransform;
|
||||
|
||||
private var sound:Sound;
|
||||
|
||||
private var playing:Boolean = false;
|
||||
|
||||
private var channel:SoundChannel;
|
||||
|
||||
private var lastStartTime:Number = 0;
|
||||
|
||||
public function SoundAdapter(owner:MediaElement, sound:Sound)
|
||||
{
|
||||
super();
|
||||
this.owner = owner;
|
||||
this.sound = sound;
|
||||
this._soundTransform = new SoundTransform();
|
||||
sound.addEventListener(Event.COMPLETE,this.onDownloadComplete,false,0,true);
|
||||
sound.addEventListener(ProgressEvent.PROGRESS,this.onProgress,false,0,true);
|
||||
sound.addEventListener(IOErrorEvent.IO_ERROR,this.onIOError,false,0,true);
|
||||
}
|
||||
|
||||
public function get currentTime() : Number
|
||||
{
|
||||
return this.channel != null ? this.channel.position / 1000 : this.lastStartTime / 1000;
|
||||
}
|
||||
|
||||
public function get estimatedDuration() : Number
|
||||
{
|
||||
return this.sound.length / (1000 * this.sound.bytesLoaded / this.sound.bytesTotal);
|
||||
}
|
||||
|
||||
public function get soundTransform() : SoundTransform
|
||||
{
|
||||
return this._soundTransform;
|
||||
}
|
||||
|
||||
public function set soundTransform(value:SoundTransform) : void
|
||||
{
|
||||
this._soundTransform = value;
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.channel.soundTransform = value;
|
||||
}
|
||||
}
|
||||
|
||||
public function play(time:Number = -1) : Boolean
|
||||
{
|
||||
var success:Boolean = false;
|
||||
if(this.channel == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.channel = this.sound.play(time != -1 ? time : this.lastStartTime);
|
||||
}
|
||||
catch(error:ArgumentError)
|
||||
{
|
||||
channel = null;
|
||||
}
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.playing = true;
|
||||
this.channel.soundTransform = this._soundTransform;
|
||||
this.channel.addEventListener(Event.SOUND_COMPLETE,this.onSoundComplete);
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.owner.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.SOUND_PLAY_FAILED)));
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.lastStartTime = this.channel.position;
|
||||
this.clearChannel();
|
||||
this.playing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() : void
|
||||
{
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.lastStartTime = 0;
|
||||
this.clearChannel();
|
||||
this.playing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function seek(time:Number) : void
|
||||
{
|
||||
var wasPlaying:Boolean = this.playing;
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.clearChannel();
|
||||
}
|
||||
this.play(time * 1000);
|
||||
if(wasPlaying == false)
|
||||
{
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private function clearChannel() : void
|
||||
{
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.channel.removeEventListener(Event.SOUND_COMPLETE,this.onSoundComplete);
|
||||
this.channel.stop();
|
||||
this.channel = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function onSoundComplete(event:Event) : void
|
||||
{
|
||||
this.lastStartTime = this.channel.position;
|
||||
this.clearChannel();
|
||||
this.playing = false;
|
||||
dispatchEvent(new Event(Event.COMPLETE));
|
||||
}
|
||||
|
||||
private function onDownloadComplete(event:Event) : void
|
||||
{
|
||||
dispatchEvent(new Event(DOWNLOAD_COMPLETE));
|
||||
}
|
||||
|
||||
private function onProgress(event:ProgressEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function onIOError(event:IOErrorEvent) : void
|
||||
{
|
||||
this.owner.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.IO_ERROR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.media.Sound;
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class SoundLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var lastBytesTotal:Number;
|
||||
|
||||
private var _sound:Sound;
|
||||
|
||||
public function SoundLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
|
||||
{
|
||||
super(loader,resource);
|
||||
}
|
||||
|
||||
public function get sound() : Sound
|
||||
{
|
||||
return this._sound;
|
||||
}
|
||||
|
||||
public function set sound(value:Sound) : void
|
||||
{
|
||||
this._sound = value;
|
||||
}
|
||||
|
||||
override protected function loadStateChangeStart(newState:String) : void
|
||||
{
|
||||
if(newState == LoadState.READY)
|
||||
{
|
||||
if(this._sound != null)
|
||||
{
|
||||
this._sound.addEventListener(Event.OPEN,this.bytesTotalCheckingHandler,false,0,true);
|
||||
this._sound.addEventListener(ProgressEvent.PROGRESS,this.bytesTotalCheckingHandler,false,0,true);
|
||||
}
|
||||
}
|
||||
else if(newState == LoadState.UNINITIALIZED)
|
||||
{
|
||||
this._sound = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function get bytesLoaded() : Number
|
||||
{
|
||||
return Boolean(this._sound) ? this._sound.bytesLoaded : NaN;
|
||||
}
|
||||
|
||||
override public function get bytesTotal() : Number
|
||||
{
|
||||
return Boolean(this._sound) ? this._sound.bytesTotal : NaN;
|
||||
}
|
||||
|
||||
private function bytesTotalCheckingHandler(_:Event) : void
|
||||
{
|
||||
var event:LoadEvent = null;
|
||||
if(this.lastBytesTotal != this._sound.bytesTotal)
|
||||
{
|
||||
event = new LoadEvent(LoadEvent.BYTES_TOTAL_CHANGE,false,false,null,this._sound.bytesTotal);
|
||||
this.lastBytesTotal = this._sound.bytesTotal;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user