Flash and Silverlight Gallery Updated Flash vs Silverlight: JavaScript Sample 2
Oct 30

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.

Vote for this sample

Flash is Better? (310 votes)
Silverlight is Better! (328 votes)

Comparison

Flash implementation: 1 hour
Silverlight implementation: 1 hour  (Implemented First)
What’s the difference?

  • Sound [AS3] vs MediaElement [C#]

Source codes

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();

Related Post

4 Responses to “Silverlight vs Flash: Audio Player”

  1. unruledboy Says:

    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.

  2. admin Says:

    really? I just can’t reproduce the bug..

  3. unruledboy Says:

    strange er? I could reproduce it every time

  4. unruledboy Says:

    did you try IE8 beta?

Leave a Reply