This is the first audio sample. It demonstrates the basic workflow of loading an external audio. You can also see the differences in pausing, replaying and seeking the audio element.
It seems that Flash has some bugs when trying to play at a specific position. You may experience that the progress bar will drop to zero when you click on the second half of the bar. However, it works perfectly in my Flash IDE and I don’t have any idea how to solve it.
Comparison
Flash implementation: 1 hour
Silverlight implementation: 1 hour (Implemented First)
What’s the difference?
- Sound [AS3] vs MediaElement [C#]
Source codes
Audio Player [Flash 9, AS3] (324.6 KiB, 1,442 hits)
Audio Player [Silverlight 2, C#] (25.3 KiB, 1,462 hits)
Flash
Silverlight
Sound [AS3] vs MediaElement [C#]
Here is a simple demonstration in manipulating an external audio.
// AS3
var _sound:Sound;
var _soundChannel:SoundChannel;
var _position:Number;
var request : URLRequest = new URLRequest(URL);
_sound = new Sound();
_sound.addEventListener(Event.COMPLETE, on_complete);
_sound.load(request);
// finish loading, play the audio
private function on_complete(e : Event):void{
_soundChannel = _sound.play();
}
// pause the audio
_position = _soundChannel.position;
_soundChannel.stop();
// replay the audio
_soundChannel = _sound.play_position;
In Silverlight, Video and Audio shared the same Class MediaElement. Don’t forget to add the object to the stage. Otherwise, you can never load the audio. Personally, I like the Audio Object in Silverlight since the API seems simpler to use.
// C#
MediaElement _mediaElement = new MediaElement();
_mediaElement.Source = new Uri(URL, UriKind.Absolute);
_mediaElement.MediaOpened += new RoutedEventHandler(_mediaElement_MediaOpened);
LayoutRoot.Children.Add(_mediaElement);
// finish loading, play the audio
void _mediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
_mediaElement.Play();
}
// pause the audio
_mediaElement.Pause();
// replay the audio
_mediaElement.Play();

October 30th, 2008 at 1:04 pm
bug with silverlight: download, play, drag the progress bar to certain place(what ever, let’s say 1 minute), it won’t play any more, no matter you clcik pause/play.
October 30th, 2008 at 1:59 pm
really? I just can’t reproduce the bug..
October 31st, 2008 at 10:53 am
strange er? I could reproduce it every time
October 31st, 2008 at 11:35 am
did you try IE8 beta?
August 15th, 2009 at 10:59 pm
Have a case in court to know to visit at, thanks!
November 20th, 2009 at 10:12 am
Thanks, this is a useful comparason. Developing a media player in Silverlight is very much easier, in fact it’s a joy. The end product is more versatile and gives better performance and a superior user experience — especially HD video with Smooth Streaming.
January 1st, 2010 at 1:06 pm
silverlight much better and the streaming is faster than flash