简体   繁体   English

在WP7上,我可以播放库中的歌曲,用mp3音频中断它,然后继续播放吗?

[英]On WP7, can I play a song from the library, interrupt it with a mp3 audio, and then resume the playback?

what I want to achieve is this: 我要实现的是:

  1. Play background music from the media library 播放媒体库中的背景音乐
  2. On a certain trigger, fade out the music, play another mp3 file (of various lengths, seconds up to a minute) 在某个触发条件下,淡出音乐,播放另一个mp3文件(各种长度,几秒钟到一分钟)
  3. After that piece of audio is played, resume previous music from the library 播放完一段音频后,从库中恢复以前的音乐

Now I run into these constraints: 现在,我遇到了以下限制:

  • In order to access and play music from the user's library, I need to use the MediaPlayer XNA class. 为了访问和播放用户库中的音乐,我需要使用MediaPlayer XNA类。
  • In order to play an arbitrary mp3 file, I need to use either MediaPlayer or MediaElement, but not SoundEffect or SoundEffectInstance 为了播放任意mp3文件,我需要使用MediaPlayer或MediaElement,但不能使用SoundEffect或SoundEffectInstance
  • If I play anything using the MediaElement, MediaPlayer stops. 如果我使用MediaElement播放任何内容,MediaPlayer将停止。 It completely loses the audio queue so I would need to play the remaining music which would be ok BUT 它完全失去了音频队列,所以我需要播放其余的音乐,但可以
  • MediaPlayer doesn't support seek so I cannot open the previous song and just go the the position before it got paused MediaPlayer不支持搜索,因此我无法打开上一首歌曲,而只能在暂停之前转到该位置

So: 所以:

  • I don't want to use SoundEffect or SoundEffectInstance as the audio would have to be wav files. 我不想使用SoundEffect或SoundEffectInstance,因为音频必须是wav文件。
  • I can't use just MediaPlayer because if I played the audio there to interrupt the song I wouldn't be able to seek to its previous position 我不能只使用MediaPlayer,因为如果我在那里播放音频来中断歌曲,那么我将无法找到它的前一个位置
  • I can't use the combination of MediaPlayer and MediaElement as MediaPlayer stops the MediaPlayer which again prevents me from resuming previous playback 我无法使用MediaPlayer和MediaElement的组合,因为MediaPlayer停止了MediaPlayer,这又使我无法继续以前的播放
  • I can't just use MediaElement because it can't play songs from the library 我不能只使用MediaElement,因为它不能播放库中的歌曲

Do you see anything I missed or is really the only option I have to suck it up and use wav files? 您看到我错过的任何东西了吗,或者真的是我必须吸收它并使用WAV文件的唯一选择吗? (There would be many of these downloaded on the fly and it is just plainly inefficient this way!) Any suggestions? (将有许多这样的文件被即时下载,以这种方式显然效率低下!)有什么建议吗?

Thanks! 谢谢!

Unfortunately you've hit a limitation of the platform. 不幸的是,您遇到了该平台的限制。

In addition to the alternative you've identified you could play the music streamed from an external source through a MediaElement. 除了确定的替代方法之外,您还可以播放通过MediaElement从外部源流式传输的音乐。 By using a timer to keep track of how much has played, when resuming the track start that far through the track by including the start point in your request to the streaming server. 通过使用计时器来跟踪播放了多少歌曲,在恢复轨道时,通过将请求中的起点包括在对流服务器的请求中,可以使起点从整个轨道开始。 This does of course mean you need to provide or find a suitable streaming capability. 当然,这确实意味着您需要提供或找到合适的流功能。 :( :(

Neither of these are ideal but for now that's the best we have. 这些都不是理想的,但就目前而言,这是我们拥有的最好的。 The background audio facilites coming in Mango may help but until details are announced we can't say for sure. 芒果中的背景音频设备可能会有所帮助,但在宣布细节之前,我们无法确定。

can't use just MediaPlayer because if I played the audio there to interrupt the song I wouldn't be able to seek to its previous position 不能只使用MediaPlayer,因为如果我在那里播放音频来中断歌曲,我将无法找到其先前位置

You will get mediastatechanged event using MediaPlayer and inthat event you could check the state of the mediaplayer and Pause the Song and then you could also Resume the song 您将使用MediaPlayer获得mediastatechanged事件,在该事件中,您可以检查媒体播放器的状态并暂停歌曲,然后还可以继续播放歌曲

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM