locked
pause/play video when App is suspended/resumed

    Question

  • Hi All,

    I am using media element in my app and referred the sample at http://code.msdn.microsoft.com/windowsapps/Media-playback-start-to-3a858ab6. everything works fine. my issue is how to pause and play the video when the app is suspended and resumed? I used oncheckpoint event and resuming event but it fails to resume.

    Any inputs on this?

    Edit: I tried using msaudiocategory="ForegroundOnlyMedia" though it pauses and plays the video without using oncheckpoint and resuming events, the video element played time will be nearly 10 secs more than the actual value. e.g: if I move to another app after 1min 45 sec of video played time, when the app is resumed(even after 10 mins) it is at 1 min 54 or 55 secs. do I need to make any other changes to overcome this issue?


    Nazia


    Tuesday, November 26, 2013 12:56 PM

Answers

  • I corrected my prior response--use document visibility in HTML/JS rather than watching for the audio being muted (guidance that works only for C#/XAML).
    Tuesday, December 3, 2013 8:31 PM

All replies

  • [Previous response was erroneous, so omitted and rewritten here.]

    Use the document.onvisibilitychange event to detect document.visibilityState == "hidden", and pause the video if that's true.

    You can then use document.visibilityState == "visible" to automatically restart playback if desired.

    Kraig

    Author, Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition, a free ebook from Microsoft Press. First edition (for Windows 8) also available.



    Tuesday, November 26, 2013 5:01 PM
  • unfortunately it didn't worked.

    I placed a breakpoint in the volumechanged event but it didn't hit. do I  need to use any other events ?


    Nazia

    Wednesday, November 27, 2013 6:09 AM
  • I corrected my prior response--use document visibility in HTML/JS rather than watching for the audio being muted (guidance that works only for C#/XAML).
    Tuesday, December 3, 2013 8:31 PM