Search Wiki:
Resource Page Description
Class libraries and example Applications to jump start development with and learning about Silverlight's MediaStreamSource.

Quick Start

To get a quick look, download Release 1.2.0.0 and look at the source in the following two projects:
  • MediaParsers.Desktop
  • Mp3MediaStreamSource.SL4

After that right click on and debug the projects:
  • Mp3MediaStreamSourceDemo.SL4
  • Mp3MediaStreamSourceDemo.Phone

Most recent update is 1.2.0.0

Changes in 1.2.0.0:
  • Added Windows Phone 7 Sample
  • Development of this code has been made public on https://github.com/loarabia/ManagedMediaHelpers
    • There are a number of issues both meaty and small and more ready to be filed and built. Please fork the code and do great things with it and send me pull requests.
    • Code releases will continue to be done on CodeGallery each time a new version of Silverlight or Silverlight based technology RTMs or when enough folks add new features to the library.
  • Code Cleanup
  • Updated Mp3MediaStreamSource to run on Windows Phone 7
  • Updated Mp3MediaStreamSource to not require reading the entire file into memory
  • Updated to support Duration
  • Updated to support streaming content

Special thanks to Stephen Lau for contributing much of this work.

Background


Why ?

This project grew out of 3 desires:
  1. Provide a MediaStreamSource sample that is useful for educating developers on development with Silverlight's MediaStreamSource
  2. Provide helper classes which make it easier to use MediaStreamSource for certain scenarios (Mp3 for now)
  3. Prime the Silverlight development community with MediaStreamSource code to see what creative things can be built

What is in this project ?

This project contains 4 things.
  1. A Silverlight class library, MediaParsers, which contains helper classes for working with Mp3 files, including tools to help find the right point in an Mp3 file to begin playback from and Managed implementations of fundamental media structures.
  2. A Silverlight Test Project built for nunit, MediaParsersTests, which provides core code coverage for the MediaParsers library.
  3. A Sliverlight class library, Mp3MediaStreamSource, which has arguably the simplest logic imaginable for using Mp3 file streams with a MediaStreamSource.
  4. A Sliverlight Application demo, Mp3MediaStreamSourceDemo and Mp3MediaStreamSourceDemoWeb, which shows the simplest interaction between a MediaElement and a MediaStreamSource.

What is a MediaStreamSource ?

The MediaStreamSource is a piece of the Silverlight runtime that removes a the influence of a media file's container, giving developers direct access to APIs for manipulating encoded elementary audio and video streams.

Why would anyone want to remove the container ?

For one thing, having access to elementary streams means that developers can now implement scenarios that other solutions haven't necessarily provided thus far. One example of this is adaptive streaming or multi-bitrate support as was seen during the 2008 Olympics.

For another reason, having access to elementary streams allows developers to implement scenarios that the Silverlight runtime hasn't had a chance to implement yet or that the runtime might not be able to implement in the same timeframe that a developer wants it. Examples of this could be, RTSP:T protocol support, SHOUTcast protocol support, seamless audio looping, ID3 v1 and ID3 v2 metadata support, and many other scenarios.

Tools used by this project

Visual Studio 2010 Ultimate
StyleCop
Windows Phone 7 Tools
git
github

Who are you?

Larry Olson
Last edited Jan 20 2011 at 10:19 PM  by loarabia, version 16
Comments
pdjplanonuance wrote  Mar 24 2009 at 6:22 PM  
I am loading a mp3 file just fine using new Uri but when i try to load the exact same file using this library, it doesn't appear to work. I'm stuffing the .mp3 into isolated storage (via file copy manually to test) and it loads the file fine, but when i'm calling SetSource() it appears to think it's a very long audio file but nothing is playing back in the MediaElement. Is there a restriction on the type of .mp3 file format this library can actually load/process???

TIA, paul

loarabia wrote  Apr 6 2009 at 6:17 PM  
Mp3 files with some metadata (ID3 v2 or ID3 v1) will frequently break the file parsing logic because this code was not made robust in any way against all the variances in Mp3 and Metadata encoding in the world. There are also a few cases where the sync logic breaks. You'd have to debug with your specific media file to determine if either of these is the case.

DaveSmits wrote  Jul 15 2009 at 1:58 PM  
is there also a manner to extend these classes to play webstreams? when i try to download a stream getting an security exception. Can't place an clientpolicy.xml because i use shoutcast and that don't serve custom files.

markkesty wrote  Sep 17 2009 at 1:00 PM  
I'm actually working with this in Silverlight 3, placing a raw PCM 16 bit audio stream in the MediaStreamSource and it plays great!

The problem is, as mentioned by someone above, that setting the position has no effect. Also, reading the current position (for example, to move a slider or display the current position in a TextBlock) gives a position which keeps increasing but is not correct. (It looks like it increments about 1 second for every 7 seconds of play). Is this a bug? Or could I be doing something wrong?

Mark

veeru wrote  Jul 21 2011 at 6:21 AM  
Can the MediaStreamSource be used to manipulate the audio in a video file? Any ideas how I can go about doing this?

Thanks,
Veeru.

Updating...
Page view tracker