locked
Yes, msAudioCategory = "BackgroundCapableMedia again RRS feed

  • Question

  • Hi, I know this question has been asked a gazillion times,but i can't seem to get the msAudioCategory = "BackgroundCapableMedia" to work, even the playback manager sample code i downloaded is not working.each time i switch to another application the background audio fades away. please kindly assist me my full code is pasted below

    Html : 

    <audio id="audtag"  autoplay="true" msaudiocategory="BackgroundCapableMedia" src="/sounds/rihana.mp3"></audio>

    Packagemanifest.xml:

    <Extensions>
            <Extension Category="windows.backgroundTasks" StartPage="default.html">
              <BackgroundTasks>
                <Task Type="audio" />
              </BackgroundTasks>
            </Extension>

    Javascript :

    // Assign the button object to MediaControls
    MediaControls = Windows.Media.MediaControl;

    // Add event listeners for the buttons
    MediaControls.addEventListener("playpressed", play, false);
    MediaControls.addEventListener("pausepressed", pause, false);
    MediaControls.addEventListener("playpausetogglepressed", playpausetoggle, false);

    // Add event listeners for the audio element
    document.getElementById("audtag").addEventListener('playing', playing, false);
    document.getElementById("audtag").addEventListener("paused", paused, false);
    document.getElementById("audtag").addEventListener("ended", ended, false);

    // Define functions that will be the event handlers
    function play() {
        document.getElementById("audtag").play();
    }
    function pause() {
        document.getElementById("audtag").pause();
    }

    function playpausetoggle() {
        if(MediaControls.isPlaying === true) {
            document.getElementById("audtag").pause();
        } else {
            document.getElementById("audtag").play();
        }
    }

    function playing() {
        MediaControls.isPlaying = true;
    }

    function paused() {
        MediaControls.isPlaying = false;
    }

    function ended() {
        MediaControls.isPlaying = false;
    }

    // Assign the button object to MediaControls
    MediaControls = Windows.Media.MediaControl;




    Wednesday, January 30, 2013 6:04 AM

Answers

  • It looks like you're missing a handler for the stoppressed event--this is required along with playpressed, pausepressed, and playpausepressed for background audio to work. The MediaControl does check that you have handlers for all four before it enabled background audio.

    Kraig

    Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press


    • Marked as answer by Song Tian Wednesday, February 6, 2013 7:43 AM
    Wednesday, January 30, 2013 5:49 PM

All replies

  • It looks like you're missing a handler for the stoppressed event--this is required along with playpressed, pausepressed, and playpausepressed for background audio to work. The MediaControl does check that you have handlers for all four before it enabled background audio.

    Kraig

    Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press


    • Marked as answer by Song Tian Wednesday, February 6, 2013 7:43 AM
    Wednesday, January 30, 2013 5:49 PM
  • Thanks!! kraig, works great...Plus i love your Book too (very resourceful).
    Wednesday, January 30, 2013 8:54 PM
  • Glad to hear it--both that you solved the problem and enjoy the book :)
    Wednesday, January 30, 2013 9:49 PM