【问题标题】:How can I pause current Zune song, play my own sound with the BackgroundAudioPlayer, then resume the Zune song?如何暂停当前 Zune 歌曲,使用 BackgroundAudioPlayer 播放我自己的声音,然后恢复 Zune 歌曲?
【发布时间】:2012-06-22 23:15:17
【问题描述】:

我正在尝试在我的一个应用程序中发出警告声音,以播放 Zune 中正在播放的任何内容。我正在使用BackgroundAudioPlayer 播放我的声音。

现在,当我的警告声音播放时,它会停止当前的 Zune 歌曲。有什么方法可以暂停 Zune 音轨,播放警告音,然后再恢复 Zune 声音?

我已经看过音频是如何工作的,所以我认为这是不可能的,只有 1 个媒体播放器,所有元素都放在一个队列中......但我很想找到一种解决方法。

【问题讨论】:

    标签: windows-phone-7 background-audio


    【解决方案1】:

    这里有一个示例:http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx

    示例正在执行此操作(注意您需要引用 XNA 并初始化 GameTimer 对象以使用 MediaPlayer 类):

    public MainPage()
    {
        InitializeComponent();
    
        // Timer to simulate the XNA game loop (SoundEffect class is from the XNA Framework)
        GameTimer gameTimer = new GameTimer();
        gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(33);
    
        // Call FrameworkDispatcher.Update to update the XNA Framework internals.
        gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } };
    
        // Start the GameTimer running.
        gameTimer.Start();
    
        // Prime the pump or we'll get an exception.
        FrameworkDispatcher.Update();
    }
    
    // Flag that indicates if we need to resume Zune playback upon exiting.
    bool resumeMediaPlayerAfterDone = false;
    
    private void ZunePause()
    {
        // Please see the MainPage() constructor above where the GameTimer object is created.
        // This enables the use of the XNA framework MediaPlayer class by pumping the XNA FrameworkDispatcher.
    
        // Pause the Zune player if it is already playing music.
        if (!MediaPlayer.GameHasControl)
        {
            MediaPlayer.Pause();
            resumeMediaPlayerAfterDone = true;
        }
    }
    
    private void ZuneResume()
    {
        // If Zune was playing music, resume playback
        if (resumeMediaPlayerAfterDone)
        {
            MediaPlayer.Resume();
        }
    }
    

    【讨论】:

      【解决方案2】:

      如您所料,不可能暂停 Zune 中正在播放的任何内容,通过 BackgroundAudioPlayer 播放曲目/声音,然后在 Zune 中恢复之前播放的曲目。

      BackgroundAudioPlayer 使用与 Zune 播放器相同的媒体队列,因此当 BAP 播放您的曲目时,队列中之前的任何内容都会被删除。即使不是,也无法从 BAP 播放(或触发播放)来自 MediaLibrary 的曲目。

      在这里使用背景音频似乎完全是错误的选择。 (或者你有理由必须使用它吗?)
      为什么不在用户已经播放的任何音频之上播放通知声音? (使用 MediaElement 或 SoundEffect。)我认为这个警告通知噪音只是一个短暂的错误哔声,所以在任何其他音乐的顶部应该没有任何问题。您可以将音频通知与 VibrateController 的使用结合起来,以帮助用户清楚地知道有问题。
      或者,由于通知是在您的应用程序运行时发出的,为什么不使用警告的视觉指示?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多