Jon Rea Jon Rea - 5 months ago 45
C# Question

Sharing Media Playback Between Pages with Windows Phone 7 Media Player

What I want to achieve:

  • I want to initiate audio playback from an mp3 and/or aac HTTP stream in a WP7 application

  • I want to initiate playback from a specific 'PhoneApplicationPage' instance, but still allow navigation to other pages whilst maintaining playback without any interuption - i.e. I want playback to be 'application-scope'

  • I want to be able to 'seek' within my media

  • I playback to continue whilst the phone is locked

What I have tried:


  • If the MediaElement is not owned by a page, no sound is produced when Play() is called, despite no exceptions being thrown.

  • After following '', playback still resets between page transitions

  • It also seems like a quite a hacky way of doing things...


  • Works, but "MediaPlayer.PlayPosition" is read-only, and there is no seek method.

  • See post: '' - Apparently this is by design due to XBox constraints with Xna (?!)

Microsoft Silverlight Media Framework:


  • My favourite option, as it seems very comprehensive

  • Downloaded 'Silverlight Media Framework 2.3, WP7 specific' assemblies from:

  • I know this is hacky, but to get something working, in the code below, the 'SMFPlayer' is static, and added to each page's layout on navigation.

  • If the 'SMFPlayer' is not owned by a page, no sound is produced when Play() is called, despite no exceptions being thrown.

  • Playback still resets between page transitions...

  • Code:

using System;
using System.Diagnostics;
using Microsoft.Phone.Controls;
using Microsoft.SilverlightMediaFramework.Core;
using Microsoft.SilverlightMediaFramework.Core.Media;
using Microsoft.SilverlightMediaFramework.Plugins.Primitives;

namespace WindowsPhoneApplication1
public partial class MainPage : PhoneApplicationPage
public static readonly SMFPlayer Player = new SMFPlayer();

static MainPage()
Player.VolumeLevel = 1.0f;
Player.Playlist.Add(new PlaylistItem {MediaSource = new Uri("", UriKind.Absolute)});

Player.LogLevel = LogLevel.All;
Player.LogEntryReceived += PlayerLogEntryReceived;

// Constructor
public MainPage()

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)

private static void PlayerLogEntryReceived(object sender, CustomEventArgs<LogEntry> e)
Debug.WriteLine(e.Value.Severity + e.Value.Message + e.Value.Type);

private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.RelativeOrAbsolute));

Does anyone have any idea how I can satisfy my requirements?
Example code?

From an architectural point of view, what I really want is a Media Service which i can send streaming URLs to without caring about which page is currently shown.

Answer Source

I eventually found a simple, but effective solution:

In App.xaml:

    <MEDIAELEMENT x:key="GlobalMedia"></MEDIAELEMENT>

In App.xaml.cs:

public static MediaElement GlobalMediaElement
  get { return Current.Resources["GlobalMedia"] as MediaElement; }

In your page:

public partial class MyPage : PhoneApplicationPage
    MediaElement MEAudio;

    public MainPage()
        MEAudio = App.GlobalMediaElement;

    private void OnSomeEvent(object sender, RoutedEventArgs e)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download