MediaCapture + CaptureElement lifecycle/navigation management

前端 未结 2 1894
走了就别回头了
走了就别回头了 2020-12-19 09:17

This is in a Windows Phone 8.1 Store app. My MainPage has a CaptureElement to display the preview stream from my MediaCapture object.

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 09:56

    You will have to use App.Suspending and App.Resuming (for the cases you have described) with combination of Navigation events (when navigating between Pages). The OnNavigatingFrom event is called when you hit Start, hold Back or use Search (when the App is being suspended), but when you resume the App, OnNavigatedTo is not being called - this event is called only when you are navigating. So in your case, when you hit Start, the preview stops and when you come back it doesn't start again. A refference to MSDN:

    Note On Windows Phone, OnNavigatedFrom() is called when the app is suspended. OnNavigatedTo() is not called when the app is resumed.

    The other thing is that to debug the App properly you will have to use Lifecycle Events of Debug Location tab in Visual Studio - while you are debbuging the app, it is not being suspended, but when you run your app normally, it gets suspended just after you hit Start.

    Note also that the App can be put into Not Running state. More about Lifecycle at MSDN.

提交回复
热议问题