2012-04-11 255 views
0

我正在爲windows phone 7開發一個應用程序。有一個媒體元素可以播放來自url的視頻。當我鎖定手機時,音頻和視頻停止播放。我試過禁用ApplicationIdleDetetction,並且我已經處理了Rootframe Obscured和Unobscured。我無法弄清楚手機鎖定時如何繼續播放音頻。Windows phone 7 - 無法播放鎖定屏幕下的音頻

對此非常感謝!

感謝 格雷厄姆

回答

0

使用AudioPlayerAgent保持音樂播放,即使手機被鎖定!

檢查Windows Phone Code Samples上的「背景音頻播放器示例」。

+0

這工作(此功能尚未在市場上,即將更新很快!)!其實我只需要調用一個BackgroundPlayer實例。謝謝 ! – jgraham 2012-04-11 18:30:37

0

當屏幕鎖定時,視頻將自動停止播放 - 這是一種內置系統功能。把它看作是一種應用程序的失效保護措施,通過在後臺播放視頻來消耗設備電池,無論如何這是一項不必要的任務 - 誰在觀看內容? ApplicationIdleDetection根本無助於此任務。

如果您有單獨的音頻流,則可以使用AudioPlayerAgent,它可用於播放本地和遠程音頻流。

閱讀本:

0

您可以使用調度計時器做到這一點。下面是我如何做到這一點在我的應用程序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; 
    } 
}