Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 10 (phone) background music question #222

Open
holospeed opened this issue Jan 19, 2017 · 13 comments
Open

Windows 10 (phone) background music question #222

holospeed opened this issue Jan 19, 2017 · 13 comments

Comments

@holospeed
Copy link

The plugin working well when I launch (debug) the app via cable from Visual Studio, but when I start the app directly from the phone the plugin donent working at all. Is someone has any idea what could be the problem ?

@katzer
Copy link
Owner

katzer commented Jan 21, 2017

@holospeed Please see cbf3f0d

However there are 2 major bugs in cordova-windows. As long as they aren't fixed, the code for windows wont be part of a release.

The plugin working well when I launch (debug) the app via cable from Visual Studio

If you do so the app will always run in background - even without the background-mode plugin.

@katzer katzer closed this as completed Jan 21, 2017
@katzer katzer reopened this Jan 21, 2017
@holospeed
Copy link
Author

Now it's clear, thank you!

@zuevalex
Copy link

zuevalex commented Feb 8, 2017

Hi, do you know if there is some workaround for this issue right now or have to wait for cordova fixes?
Thanks for your plugin!

@katzer
Copy link
Owner

katzer commented Feb 9, 2017

@zuevalex, only manually. I want to avoid the usage of hook scripts as they aren't supported by PGB.

@jonnysmith1981
Copy link

jonnysmith1981 commented Apr 21, 2017

What is the manual process?

I have installed cordova-windows 5.0.0 which should include the resource-file copy fix.
I have also added backgroundMediaPlayback to the list of CAPS_NEEDING_UAPNS.
I have also uncommented the windows section from the plugin.xml

The background mode plugin does not appear in the Cordova commandProxyMap so the call to backgroundMode.enable() fails silently.

What else am I missing?

@jonnysmith1981
Copy link

When I try to build my windows project i get this:
D:\Development\bgtest\platforms\windows\build\windows\debug\anycpu\win10\AppxManifest.xml : error APPX0501: Validation error. error C00CE169: App manifest validation error: The app manifest must be valid as per schema: Line 42, Column 21, Reason: 'backgroundMediaPlayback' violates enumeration constraint of 'documentsLibrary picturesLibrary videosLibrary musicLibrary enterpriseAuthentication sharedUserCertificates userAccountInformation removableStorage appointments contacts phoneCall blockedChatMessages objects3D voipCall chat'. The attribute 'Name' with value 'backgroundMediaPlayback' failed to parse. [D:\Development\bgtest\platforms\windows\CordovaApp.Windows10.jsproj]

@holospeed
Copy link
Author

I guess you are building your project with Visual Studio. If you are than you have to build the chosen platform not the root project. Let me explain: 1, launch visual studio 2,File 3, Open 4, Project/Solution, 4, brows to: YOUR_CORDOVA_APP/platforms/windows/ and chose the solution file (for example: CordtovaApp.windows10). when its open click on package.windows10.appxmanifest, (its must be on the right side) chose Capabilities, click on the Background Media Playback checkbox . Build the solution and it would work!

1
2
3
4

@scottlikestech
Copy link

Thank you. These last steps now have my Windows Phone running in the background.

However, one of the tasks in the background is to make http calls to a REST WCF service every few minutes or so. I use the same code as used when the app is in the foreground; the $http.post angular method. When in the background it always fails. To rule out any issues WCF server side, I change it to GET requests just calling public urls like google, etc but it still fails with no exception data to go on. Resume from the background into the foreground and the calls start working again.

Without changing the application so that the server is calling the client instead with push notifications, is there any way of making the $http.post angular method work in the background or is there another client-side method available?

@oduis
Copy link

oduis commented Oct 26, 2017

Hello scottlikestech,

I am at the same stage now. While enabling backgroundMode for keeping the app alive, the http post fails.
Did you solve the problem back then?

Thanks in advance
Oliver

@scottlikestech
Copy link

Yes Oliver I solved it. The workaround was based on a flaw observed in the original .NET Mobile Framework when I was doing natives Windows Mobile apps back in 2008. I did not expect the same trick to work but it did.

Before I go into the detail, you need to be aware that Microsoft recently issued a statement and are basically throwing Windows Mobile down the toilet. The plugin authors in turn will no doubt cease support for this platform, just a question of when, and then whatever app you are building with whatever plugins, you may find yourself with an app you cannot support long term.

If after considering all this you still want the fix then let me know.

@oduis
Copy link

oduis commented Oct 28, 2017

I am aware WM10 is dead. I do a training project to test the virtues of Ionic/Angular4 on a personal project where I still use my Win10 mobile.
I'd be grateful if you could share some details.

@scottlikestech
Copy link

This is assuming you have followed the above steps and have background working on Windows. I won't go over that.

When making calls in Windows in background mode, it will soon keep coming back with a http status of -1. When this happens, have it run run the following code and substitute the hyperlink in the GET call with a method call on the same service as you are calling to get your app's new data in the background. Keep it as a GET call. It does not matter what this "mymethod" does, maybe it just returns the current date, just make it a different call than what the app needs to do.

for (var i = 1; i <= 2; i++) {
setTimeout(function () {
var invocation = new XMLHttpRequest();
invocation.timeout = 100000;
invocation.open('GET', 'https://myserviceurl.com/myservice/mymethod', true);
invocation.onreadystatechange = function (evtXHR) {
if (invocation.readyState === 4) {
// change console.log() to permanent storage where so you can see that this works
console.log('status=' + invocation.status + ', responseText=' + invocation.responseText);
}
};
invocation.send();
}, 2000);
}

The above code makes 2 hits, 2 seconds apart. From my trial and error this works best than just one call by itself, but without being too excessive and wearing out the battery. Whether these "resuscitator calls" work or fail, you suddenly find that your next call to the actual service method you want to call in the background works, or the one after it works. Your app must cater for the intermittent issue; not all calls will work even with this fix.

Once you have this working, this is not the end of the issue. You will find that after 15 minutes the app, even with background notifications working, stops running in the background after 15 minutes anyway. To prevent this from happening, have an interval that runs every 10 minutes, activated only when in the background mode, that will launch an on-screen notification to the user, which the user won't see if the app is in the background anyway but keeps the app alive. DO NOT do this as an actual screen notification that will pop up to the user on their phone from background mode; it will annoy the user and drain the battery.

@oduis
Copy link

oduis commented Oct 29, 2017

scottlikestech, thank you very much for your help! I appreciate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants