views:

149

answers:

3

I have a SL4 project that is successfully streaming a great sounding WMA audio stream from a remote location. All of the MediaElement actions are straight forward.

What I want to do is read the attributes that are passed as text along with the Audio stream. For instance the encoder of the stream embeds the title of the stream, the title of the song playing and the name of the artist for the current song.

How would I pick this out using Silverlight 4 and then display it in a Label to the user?

It sure would be easier than writing a bunch of web services to do the same thing. Windows Media Player and WinAmp all get the information I am just not seeing it in the MediaElement object collection.

A: 

Mayba WMP and WinAmp get the Informations from a Website or something like this, and dont read it out of the stream...

Werewolve

Werewolve
No, that's not right because the stream information is read in WMP directly out of my stream. WMP and WinAmp get the information from a website only to update a local music library.
Brent Pabst
A: 

Tim Heuer has a post on this topic.

David
David, thanks for the help although this is not it either. Tim is dealing with again a local music library and getting the file settings that way. I don't have this as part of a live audio stream. I did find the answer to my problem and will post it in a few minutes.
Brent Pabst
A: 

I found the answer after searchting the web as well as fiddling with Expression 3 a little as well.

It turns out that a live audio stream has markers that are sent across as well as the audio. Markers can contain almost anything but one is called a "Caption". The caption is basically a free-form string field that you can read. With my stream the encoder sends a lot of information across as a caption that can then be broken down. So here is the code I am using:

Starts with registering a few events, the last one is the important one.

public MainPage()
    {
        InitializeComponent();
        this.mediaElement1.BufferingProgressChanged += new RoutedEventHandler(mediaElement1_BufferingProgressChanged);
        this.mediaElement1.MarkerReached += new TimelineMarkerRoutedEventHandler(mediaElement1_MarkerReached);
    }

Then the actual marker handler does the following:

private void mediaElement1_MarkerReached(object sender, TimelineMarkerRoutedEventArgs e)
    {
        Dictionary<string, string> songAttribs = new Dictionary<string, string>();
        string playerFeed = HttpUtility.UrlDecode(e.Marker.Text);
        char[] delims = { '&' };
        string[] Attribs = playerFeed.Split(delims);

        foreach (String attrib in Attribs)
        {
            string[] keypair = attrib.Split('=');
            string key = "";
            string value = "";

            try
            {
                key = keypair[0];
            }
            catch
            {
                key = null;
            }

            if (key != null)
            {
                try
                {
                    value = keypair[1];
                }
                catch
                {
                    value = "";
                }

                songAttribs.Add(keypair[0], keypair[1]);
            }
        }

        nowplaying.Title = songAttribs["title"];
        nowplaying.Artist = songAttribs["artist"];
        nowplaying.Duration = 0;

        this.label2.Content = "Artist: " + nowplaying.Artist;
        this.label3.Content = "Title: " + nowplaying.Title;

        this.label1.Content = playerFeed;
    }

Still working on some of the code but so far things seem to be working.

Brent Pabst