How to make MediaElement visible when playing audio file mp3?

I have XAML as ContentControl:

<ContentControl x:Name = "MyPlayer">      
  <StackPanel />
</ContentControl>

Then I add MediaElement in code for this ContentControl:

this.myPlayer.Content = new MediaElement() {
 Source = new Uri(@"http://mysite/myfile.mp3"),
 Visibility = Visibility.Visible
};

Then when I run the app, the player does play the file, but there is no visual player. The screen stays blank.

How to put a visual player element so that user can pause/stop/replay the source?


You need to create your own buttons and code behind logic to play/pause/replay etc. You can use this as a reference: http://msdn.microsoft.com/en-us/library/ms748248.aspx

Alternatively, you can use the CodePlex Media Player Framework: http://smf.codeplex.com/ This has created templates for media players.

I believe you also need to specify a height/width for the MediaElement if you want to see something, though what are you expecting to see for an MP3 file?

Also, what is the need for the ContentControl? Why don't you put the MediaElement in the xaml?

链接地址: http://www.djcxy.com/p/41792.html

上一篇: 如何在Android中完美地使用MediaPlayer

下一篇: 如何在播放音频文件mp3时使MediaElement可见?