WP7 gapless music from MediaPlayer when using mediaElement

I'm trying to make a text reader for my WP7. I'm using a mediaElement in my reader. at first every time the app read something, the MediaPlayer stopped, as I later discovered that is how it is designed. Then I tried to try and trick the system, by using

mediaElement1.Stop();
mediaElement1.SetSource(isolatedStorageFileStream);
FrameworkDispatcher.Update();
MediaPlayer.Pause();
mediaElement1.Play();
if (mpState != MediaState.Stopped)
{ MediaPlayer.Resume(); }

now comes the wierd part, when I use the reader once, it reads and the music seems to run without any pause, as I wanted, but when I use the reader for the second time, the MediaPlayer stops to play. when I've added some breakpoints, I've noticed that after the first read, the MediaPlayer.state is paused, but it still plays. I have some kind of a media player in my app, so I have some listBoxes that are filters, I want to read to selected filer (artist, album, etc.). so basically using the reader happens when selected item is changed. I'm using both MediaPlayer and MediaElement because if i won't pause the mediaPlayer, it will stop, and I will lose the position of the playing song. and because I want the reader to play gapless I'm using a mediaElement. I'm lost...


Try looking at this (Music + Videos Hub Sample) http://go.microsoft.com/fwlink/?LinkID=203588 which I think you already use (using the media libraries on the phone), but try combining it with this (Silverlight Sound Sample) http://go.microsoft.com/fwlink/?LinkID=207868, which shows how to use XNA to play sounds in parallel.

If you carefully mix & match these 2 examples, you can achieve what you want, I've just tried it myself. Simply copied all that's needed from example 1 into example 2, and it works just fine: the background music plays, and the birds happily chirp without harming one another.

Let me know if you have problems with it.

BTW - over here: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx you have many working examples, for many different things. I took both examples above from this link.

Eyal

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

上一篇: WP7同时/动态地播放许多压缩(mp3,wma等)音频文件

下一篇: 使用mediaElement时,来自MediaPlayer的WP7无间隙音乐