다음을 통해 공유


How to use the Media Player launcher for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Use the Media Player Launcher to start the media player and play the media file you specify. You must specify the name and location of the file. You can optionally specify one or more of the Media Player controls, such as rewind and stop, by using a bitwise combination of the controls. You can also specify a preferred orientation to use when the Media Player starts.

By using Launchers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.

Note

On Windows Phone Emulator, the application can start the Media Player and the user can play music, but video is not rendered.

To use the Media Player Launcher

  1. Add the following statements to your code.

    using System;
    using Microsoft.Phone.Tasks;
    
    Imports Microsoft.Phone.Tasks
    
  2. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.

    MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();
    
    mediaPlayerLauncher.Media = new Uri("MyVideo.wmv", UriKind.Relative);
    mediaPlayerLauncher.Location = MediaLocationType.Data;
    mediaPlayerLauncher.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop;
    mediaPlayerLauncher.Orientation = MediaPlayerOrientation.Landscape;
    
    mediaPlayerLauncher.Show();
    
    Dim mediaPlayerLauncher as MediaPlayerLauncher = new MediaPlayerLauncher()
    
    mediaPlayerLauncher.Media = new Uri("MyVideo.wmv", UriKind.Relative)
    mediaPlayerLauncher.Location = MediaLocationType.Data
    mediaPlayerLauncher.Controls = MediaPlaybackControls.Pause Or MediaPlaybackControls.Stop
    mediaPlayerLauncher.Orientation = MediaPlayerOrientation.Landscape
    
    mediaPlayerLauncher.Show()
    

Note

Use MediaLocationType.Data for media files that are stored in isolated storage. Use MediaLocationType.Install for media files that are part of the application project. They are bundled into the .xap file and stored in the installation directory of the application.

See Also

Reference

MediaPlayerLauncher

MediaLocationType

MediaPlaybackControls

Other Resources

Media for Windows Phone