2012-08-01 151 views

回答

1
<!xaml code in Main Page> 
<MediaElement Name="mediaElement" 
         Source="xxxxxxxxxxxxxxxxxxxxxxx" 
         AutoPlay="False" 
         MediaOpened="OnMeenter code herediaElementMediaOpened" 
         MediaFailed="OnMediaElementMediaFailed" 
         CurrentStateChanged="OnMediaElementCurrentStateChanged" /> 

    <!to play media by on click event> 
    <shell:ApplicationBarIconButton 
    IconUri="Images/appbar.transport.play.rest.png" 
    Text="Play" 
    Click="OnAppBarPlayClick" /> 


<!this is based on click event> 
void OnAppbarPlayClick(object sender, EventArgs args) 
{ 
mediaElement.Play(); 
} 


//assign this code in main page 

public MainPage() 
{ 

InitializeComponent(); 
// Re-assign names already in the XAML file 
appbarPlayButton = this.ApplicationBar.Buttons[1] as ApplicationBarIconButton; 
}