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

2

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?

html
windows-phone-8
win-universal-app
asked on Stack Overflow Sep 1, 2014 by Aquinas

2 Answers

1

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

answered on Stack Overflow Sep 2, 2014 by Aquinas
1

WindowsPhone 8.1 do not support background audio by JavaScript. You should use c# for this task. That is all.

"Important:

You can use JavaScript to write background audio applications. However, Windows Phone 8.1 does not allow JavaScript to run in a background process. Which means, your foreground app and UI can be written in JavaScript, but your background task must be written in C# or C++. The Background audio for Windows Phone 8.1 sample provides an example of a JavaScript app that supports background audio by using a C# background agent."

https://msdn.microsoft.com/en-us/library/windows/apps/dn720802.aspx

answered on Stack Overflow Nov 25, 2015 by Vasyl

User contributions licensed under CC BY-SA 3.0