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

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?

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

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

Related

Windows RT/ Universal app, Webview offline html file

( creating a universal app, currently working one windows phone 8.1) I am trying to get the webview to work with an offline html file but i cant really figure it out. I can get it to work with a weblink but not with an html file which is located on the shared folder.
I'm using switch statement to switch through different options. Here is a sample one with the code i use
case "Test":
ActualLoad = "Test.html";
break;
Here is the one that has a link:
case "OnlineTest":
ActualLoad = "https:www.google.com";
break;
The second one works but not the first one.
Check out the Remarks in this MSDN page.
Basically, you have to use something like this: <WebView Source="ms-appx-web:///Test.html"/>
This will work only if your Test.html file exists in your app package.

Windows Runtime equivalent to the Silverlight PhoneSubtleBrush

In Silverlight there is the PhoneSubtleBrush which is the color used in the Mail app to display the message excerpt below the subject.
Is there something in the Windows Runtime API that has the same color as PhoneSubtleBrush?
Not sure if it's exactly the same but I've been using ListViewItemSubheaderTextBlockStyle so far.

how to play audio through earpiece only in windows phone 8 application

I have tried with AudioRoutingManager class...but i got unauthorizedaccess exception.
here is my code
AudioRoutingManager audioRouting = AudioRoutingManager.GetDefault();
public AudioRoutingEndpoint ChangeAudioRoute()
{
var currentEndPoint= audioRouting.GetAudioEndpoint();
switch (currentEndPoint)
{
case AudioRoutingEndpoint.Earpiece:
case AudioRoutingEndpoint.Default:
return AudioRoutingEndpoint.Speakerphone;
case AudioRoutingEndpoint.Speakerphone:
return AudioRoutingEndpoint.Earpiece;
default:
throw new OperationCanceledException();
}
}
public void SetAudioRoute()
{
audioRouting.SetAudioEndpoint(this.ChangeAudioRoute());
}
The APIs in the Windows.Phone.Media.Devices namespace require the ID_CAP_AUDIOROUTING and the ID_CAP_VOIP capability. (Add this to your manifest)
Also, it's only possible to change the audio routing while in a active VOIP call.
Additionally, you need to do the audio routing in your background VOIP process, and not in the foreground process.
Old question but now I know the answer.
Two things which you need to do:
Tag the audio in question as "communications"
How to do this depends on what API you're using. It could be as simple as . Or you might have to call IAudioClient2::SetClientProperties with an AudioClientProperties structure whose AudioClientProperties.eCategory = AudioCategory_Communications.
Tag your app as either a "voice over IP" app or a "voicemail" app
You should add file called WindowsPhoneReservedAppInfo.xml to your project with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<WindowsPhoneReservedAppInfo xmlns="http://schemas.microsoft.com/phone/2013/windowsphonereservedappinfo">
<SoftwareCapabilities>
<SoftwareCapability Id="ID_CAP_VOIP" />
</SoftwareCapabilities>
</WindowsPhoneReservedAppInfo>
Look for more detailed explanation here:
Playing audio to the earpiece from a Windows Phone 8.1 universal app

Html from Silverlight (not out of browser)

I am trying to open HTML file from the local URI which I use as XML Editor, to edit xml data that come from Silverlight application, then close browser window and return back edited xml data to the Silverlight application.
I tried to use HtmlPage.Window.Navigate but I don't quit like it.
I have tried using a method from: http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx
but instanly got an exception "failed to invoke ShowJobPlanIFrame"
Is there any way to handle this task?
"Out of browser" mode doesn't fit.
Thanks.
===========================================================================
Update:
It worked out using IFrame overlay.
Button click invokes the following code in C#:
var scriptObject = (ScriptObject)HtmlPage.Window.GetProperty("ShowJobPlanIFrame");
scriptObject.InvokeSelf(url);
Where "ShowJobPlanIFrame" is as defined at:
http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx
This allowed me to pass data into XML editor and then get it back.
An error with JavaScript function invocation I told above, was my fault in JavaScript code itself.
A very similar scenario: https://stackoverflow.com/a/7919065/384316
Try using an iframe overlay, then you can load any HTML-like content.
There is an excellent explanation of how to do this here:
http://www.wintellect.com/cs/blogs/jlikness/archive/2010/09/19/hosting-html-in-silverlight-not-out-of-browser.aspx
It worked out using IFrame overlay.
Button click invokes the following code in C#:
var scriptObject = (ScriptObject)HtmlPage.Window.GetProperty("ShowJobPlanIFrame");
scriptObject.InvokeSelf(url);
Where "ShowJobPlanIFrame" is as defined at:
http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx
This allowed me to pass data into XML editor and then get it back.
An error with JavaScript function invocation I told above, was my fault in JavaScript code itself.
Did you try NavigationFramework of Silverlight? It's capability may support your needs in a more simple way than using multiple browser pages.

Possible channels of communication between Javascript on HTML page and a windows EXE?

Here's the thing.
A two-way communication (RPC-style) is needed between JavaScript on HTML pages provided by a web server online (with session-management and whatnot) and a windows EXE application running on the PC of the website visitor.
Both are parts of the same 'package' and should be able to communicate.
There is the use of a custom protocol for sure, but some browsers like Chrome & Safari sometimes have issues with custom protocol handling, so it is not reliable enough ...
Another possibility is to build a minimal web-server inside the EXE, so the communication would work with all browsers.
It is possible to develop an extension / plugin for each browsers separately, but it's a daunting task..
The usage of flash / java seems not possible for this task because of sandboxing, but I'm not sure about this ??
Do you have any other ideas ?
You can use an embedded ActiveX (COM) object and communicate between both platforms. I've done it (and would not have believed it possible had I not). It's nasty but it works. In the project I used it on I had no choice (which is about the only reason to ever do this). I built the COM object in C#.net and exposed an interface to COM for use on the page. It goes something like this:
function doSomethingInteresting() {
// in your js:
var obj = document.getElementById('yourObjectId');
obj.MethodNameDefinedOnYourCOMObject("someParameterValue");
}
// and your HTML looks like this; note that you can even catch events thrown from the COM object in Js...
<body>
<form>
<object id="yourObjectId" height="0" width="0" classid="clsid:99999999-9999-9999-9999-999999999999" onerror="oError()" VIEWASTEXT></object>
<script for="yourObjectId" event="ThisIsTheJavaScriptEventHandlerMethod(parameterName)" language="javascript">
// event handling here for the COM object
function yourObjectId::ThisIsTheJavaScriptEventHandlerMethod(parameterName) {
// you can process the parameterName passed from the object here
}
</script>
</form>
</body>
Happy coding!