【问题标题】:Windows phone 7 - unable to play audio under lock screenWindows phone 7 - 无法在锁定屏幕下播放音频
【发布时间】:2012-04-11 14:36:56
【问题描述】:

我正在为 windows phone 7 开发一个应用程序。有一个媒体元素可以从 url 播放视频。当我锁定手机时,音频和视频停止播放。我已经尝试禁用 ApplicationIdleDetetction 并且我已经处理了 Rootframe Obscured 和 Unobscured。我只是不知道如何在手机锁定时继续播放音频。

非常感谢任何帮助!

谢谢 格雷厄姆

【问题讨论】:

    标签: windows-phone-7 video-streaming mediaelement lockscreen


    【解决方案1】:

    使用AudioPlayerAgent即使手机被锁定也能继续播放音乐!

    查看Windows Phone Code Samples 上的“背景音频播放器示例”。

    【讨论】:

    • 成功了!!实际上我所要做的就是调用一个 BackgroundPlayer 实例。谢谢!
    【解决方案2】:

    屏幕锁定时视频将自动停止播放 - 这是系统内置功能。将其视为通过在后台播放视频会耗尽设备电池的应用程序的故障保护,无论如何这是一项不必要的任务 - 谁观看内容? ApplicationIdleDetection 对这项任务毫无帮助。

    如果您有单独的音频流,您可以使用AudioPlayerAgent,它可用于播放本地和远程音频流。

    阅读:

    【讨论】:

      【解决方案3】:

      您可以使用调度程序计时器来执行此操作。这是我如何在我的应用程序 Searchler 中执行此操作的示例(此功能尚未在市场中,更新即将推出!)使用可用的 MMP 播放器框架@http://smf.codeplex.com/

      namespace Searchler.Views
      {
          public partial class PlayerView : PhoneApplicationPage
          {
              bool appUnderLock = false;
              DispatcherTimer dispatcherTimer = new DispatcherTimer();
          }
      
           public PlayerView()
          {
      
              InitializeComponent();
      
              //Hack to enable play under lock screen
              UIThread.Invoke(() => VideoPlayer.PlayStateChanged += VideoPlayer_PlayStateChanged);
              UIThread.Invoke(() => (Application.Current as App).RootFrame.Obscured += RootFrame_Obscured);
              UIThread.Invoke(() => (Application.Current as App).RootFrame.Unobscured += RootFrame_Unobscured);
              dispatcherTimer.Tick += dispatcherTimer_Tick;
              dispatcherTimer.Interval = new TimeSpan(0, 0, 3); 
          }
      
          void dispatcherTimer_Tick(object sender, EventArgs e)
          {
              if( VideoPlayer.PlaybackPosition == VideoPlayer.EndPosition)
                  ((PlayerViewModel)DataContext).Next();  //Custom GetNext Video Method
          }
      
          void RootFrame_Unobscured(object sender, EventArgs e)
          {
              dispatcherTimer.Stop();
              appUnderLock = false;
          }
      
          void RootFrame_Obscured(object sender, ObscuredEventArgs e)
          {
              dispatcherTimer.Start();
              appUnderLock = true;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-30
        • 2020-09-23
        • 2011-12-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多