Free ly thinking: MediaPlayerLauncher, how to use in your WP7 Projects

Thanks to the kindness of Kenny Spade, see his blog at https://blogs.msdn.com/kennyspade, I would still have been stumped/confused about how to implement the MediaPlayerLauncher in XNA. (Kenny is one awesome person!)

Kenny was kind enough to provide the following code:

         protected override void LoadContent()
         {
             spriteBatch = new SpriteBatch(GraphicsDevice);      
             MediaPlayerLauncher mpl = new MediaPlayerLauncher();         
  
             mpl.Location = MediaLocationType.Install;
             mpl.Media = new Uri("Videos/trailer_iphone.m4v", UriKind.Relative);
             mpl.Controls = MediaPlaybackControls.None;
             mpl.Show();
           
         }

Which appears to be similar to the sample code, but with a difference, note that it is in the LoadContent and not the page constructor as the sample at

https://msdn.microsoft.com/en-us/library/hh394004(v=VS.92).aspx .

The emulator in debug mode doesn't quite work as expected, but if you load the XAP file directly to the emulator it works in a manner similar to the phone.

If you use the code in the LoadContent, (as shown above) the player doesn’t always appear, but if you place in the page constructor, then it does appear in all 8 times I tried the code.

It would be better to put the code in a drawable component class, but for now, well, it would do the trick if you are looking for a way to launch a splash video for the Imagine Cup or just want to get that seasonal game into the marketplace (kind of late for Halloween, but Thanksgiving or ??? is coming up fast).

 public Game1()
         {
             graphics = new GraphicsDeviceManager(this);
             Content.RootDirectory = "Content";
  
             // Frame rate is 30 fps by default for Windows Phone.
             TargetElapsedTime = TimeSpan.FromTicks(333333);
  
             // Extend battery life under lock.
             InactiveSleepTime = TimeSpan.FromSeconds(1);
             MediaPlayerLauncher mpl = new MediaPlayerLauncher();
  
             mpl.Location = MediaLocationType.Install;
             mpl.Media = new Uri("Videos/trailer_iphone.m4v", UriKind.Relative);
             mpl.Controls = MediaPlaybackControls.Stop;
             mpl.Show();
         }

Well have fun.