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.

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

Shares and Enjoy~

Did you like this post?

Subscribe here:  

13 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?

  5. beegaid Says:

    Have a case in court to know to visit at, thanks!

  6. Tim Acheson Says:

    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.

  7. sam Says:

    silverlight much better and the streaming is faster than flash

  8. Codeman862 Says:

    The siverlight version sounds cleaner

  9. Friendsmaza Says:

    http://www.Tvhind.com

  10. Anton Says:

    Did you see silverlight audio player anywhere? There are no silverlight players in the internet

  11. Welt Says:

    Yeah, there are plenty

  12. ray lewis jersey Says:

    4…

    “BanXie” is the ground type of board type shoes. It comes from the skateboard people wear shoes, so also called skateboarding shoes. BanXie compared with general shoes, different place is: it is almost a flat bottom, easy to let feet are able to comp…

  13. UGG 5854 Says:

    3…

    OAKLEY glasses glasses products on the concept of subversion is that it is the glasses comfortable, practical, artistic fusion of one. Whether it is product design or choice of materials, have been a series of advanced scientific experiments and testin…

Leave a Reply