locked
Universal App (HTML5) deployment to Windows Phone fails when using Background Audio

    Question

  • I am developing a Universal App that uses the HTML5 / JavaScript framework. In this app I have a page with an HTML audio tag (with the attribute msAudioCategory set to "BackgroundCapableMedia"), that is further wired up with Windows.Media.SystemMediaTransportControls.getForCurrentView() in order to get the audio playing in the background. I also have, on both the windows and phone projects, set the Declarations > Background Tasks > Audio, with the default.html page set as the entry page.

    Deploying to Windows (either local machine or emulator) works as expected. All to the good. However deploying to either the phone emulator or a physical phone device throws this rather unhelpful error:

    Unexpected Error: Package could not be registered. (Exception from HRESULT: 0x80073CF6)

    Cant see any obvious reason for this. Searching the net suggests that this might be a bug, but I also suspect that playing background audio on the phone might require a different methodology.

    Notably, starting a new blank universal app, adding the declaration as above (with no audio tag or supporting code), deploys on windows but fails with the same error on the phone. Any ideas?

    Tuesday, September 2, 2014 4:09 AM

Answers

  • Have discovered the issue that the rather uninformative error was trying to tell me: my entry point was invalid. As mentioned I had it set it to the default.html page, but for the windows phone at least it needs to be set to a valid background task file. In C# this is something that inherits from the Windows.ApplicationModel.Background.IBackgroundTask interface. In JavaScript, this is a JS file that looks a little like this:

        (function () {

     var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;

     function doWork() {

      var settings = Windows.Storage.ApplicationData.current.localSettings;
      var key = backgroundTaskInstance.task.taskId.toString();
      settings.values[key] = "Succeeded";

      close();
     }

     if (!canceled) {
      doWork();
     } else {

      key = backgroundTaskInstance.task.taskId.toString();
      settings.values[key] = "Canceled";

      close();
     }

         })();

    Taken from the sample here: http://msdn.microsoft.com/en-us/library/windows/apps/hh977045.aspx

    Cheers :D

    Tuesday, September 2, 2014 9:08 PM

All replies

  • Have discovered the issue that the rather uninformative error was trying to tell me: my entry point was invalid. As mentioned I had it set it to the default.html page, but for the windows phone at least it needs to be set to a valid background task file. In C# this is something that inherits from the Windows.ApplicationModel.Background.IBackgroundTask interface. In JavaScript, this is a JS file that looks a little like this:

        (function () {

     var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;

     function doWork() {

      var settings = Windows.Storage.ApplicationData.current.localSettings;
      var key = backgroundTaskInstance.task.taskId.toString();
      settings.values[key] = "Succeeded";

      close();
     }

     if (!canceled) {
      doWork();
     } else {

      key = backgroundTaskInstance.task.taskId.toString();
      settings.values[key] = "Canceled";

      close();
     }

         })();

    Taken from the sample here: http://msdn.microsoft.com/en-us/library/windows/apps/hh977045.aspx

    Cheers :D

    Tuesday, September 2, 2014 9:08 PM
  • Hi Chris,

    Looks like your issue have been solved, I will close this thread. If you have further questions, please feel free to post on the forum. Thanks

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, September 3, 2014 7:26 AM
    Moderator