Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20035] Windows:Ti.Media.AudioPlayer => allowBackground has no effect

GitHub Issuen/a
TypeBug
PriorityCritical
StatusResolved
ResolutionWon't Do
Resolution Date2020-06-30T14:48:35.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sn/a
ComponentsWindows
Labelsallowbackground, audioPlayerAPIs, win
ReporterUwe Endesfelder
AssigneeChristopher Williams
Created2015-08-04T09:42:59.000+0000
Updated2020-06-30T14:48:35.000+0000

Description

the stream starts and plays, but if the app goes to background (tap on windows-button) or device goes into looked-mode the stream stops. the stream starts to play again if the app returns to the foreground. the "allowBackground" feature is set in the doc as available for windows from version 4.1.0.

Comments

  1. Radamantis Torres-Lechuga 2015-08-07

    [~endomedia] please attach a test case and steps to reproduce this issue
  2. Uwe Endesfelder 2015-08-10

    *Sample Code:*
       var audioPlayer = Ti.Media.createAudioPlayer({
       	url:				'http://streams.rsa-sachsen.de/rsa-live/mp3-192/mediaplayerrsa',
       	allowBackground:	true,
       });
       audioPlayer.setAllowBackground(true);
       var win = Titanium.UI.createWindow({
           title:				'winstream',
           backgroundColor:	'#ccc',
       });
       var button = Titanium.UI.createButton({
           title:				'play',
       });
       button.addEventListener('click',function() {
       	audioPlayer.start();
       });
       win.add(button);
       win.open();
       
    And here is a short videoclip from the behaviour on a real windowsphone-device: http://www.endomedia.de/appc/winstream.mp4
  3. Gary Mathews 2015-12-09

    PR: https://github.com/appcelerator/titanium_mobile_windows/pull/497
  4. Harry Bryant 2016-04-13

    [~gmathews] tested on both windows 8.1 & 10.0 phones and allowBackground does not seem to work, Included the extension in the tiapp.xml and used your sample code, am I missing anything else? on the windows 10 phone I receive the following error when trying to play the stream with allowBackground set to true :
       // Some comments here
       public String getFoo()
       [ERROR] Application Error: "Runtime Error during click event: unknown exception"
       
    Tested on: Windows 10 Pro Windows Phone 10.0 & 8.1 (Microsoft Lumia 640 LTE) Appc Studio: 4.6.0.201604081249 Ti SDK: 5.3.0.v20160413061223 Appc NPM: 4.2.5-1 Appc Core: 5.3.0-12 Node: v4.4.2
  5. Gary Mathews 2016-04-30

    [~htbryant] Try this in your tiapp.xml, it includes Executable="$targetnametoken$.exe"
       <windows>
         <manifest>
           <Extensions>
             <Extension Category="windows.backgroundTasks" Executable="$targetnametoken$.exe" EntryPoint="TitaniumWindows_Media.AudioBackground">
               <BackgroundTasks>
                 <Task Type="audio" />
               </BackgroundTasks>
             </Extension>
           </Extensions>
         </manifest>
       </windows>
       
  6. Harry Bryant 2016-05-05

    [~gmathews] I've included the revised tiapp.xml, and allowBackground still has no effect on a Windows 10 device. The build fails completely when attempting to deploy to a Windows 8.1
       [ERROR] :  C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\Package.appxmanifest(55,8): error APPX1668: App manifest contains a background task contract which uses executable 'ThursdayTest2.exe', but does not specify task type 'Control Channel' or 'Push Notification'. Leave the field blank instead. [C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.vcxproj]
       [TRACE] :  Done Building Project "C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.vcxproj" (default targets) -- FAILED.
       [TRACE] :  Done Building Project "C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.vcxproj.metaproj" (default targets) -- FAILED.
       [TRACE] :  Done Building Project "C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.sln" (default targets) -- FAILED.
       [DEBUG] :  Build FAILED.
       [DEBUG] :  
       [ERROR] :  "C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.sln" (default target) (1) ->
       "C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.vcxproj.metaproj" (default target) (2) ->
       "C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.vcxproj" (default target) (6) ->
       (_ValidateAppxManifest target) -> 
         C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\Package.appxmanifest(55,8): error APPX1668: App manifest contains a background task contract which uses executable 'ThursdayTest2.exe', but does not specify task type 'Control Channel' or 'Push Notification'. Leave the field blank instead. [C:\Users\test\.titanium\vsbuild\ThursdayTest2\phone.ARM\ThursdayTest2.vcxproj]
           0 Warning(s)
           1 Error(s)
       Time Elapsed 00:00:27.50
       
    Tested on: Windows 10 Pro Windows Phone 10.0 & 8.1 (Microsoft Lumia 640 LTE) Appc Studio: 4.6.0.201605030516 Ti SDK: 5.3.0.v20160503133640 Appc NPM: 4.2.5-5 Appc Core: 5.3.0-43 Node: v4.4.2
  7. Gary Mathews 2016-05-06

  8. Harry Bryant 2016-05-12

    [~gmathews] that issue has been addressed but including Executable="$targetnametoken$.exe" still causes that error on 8.1. Additionally, allowBackground remains to have any effect whatsoever on windows 10 phones, here is the following test case performed: 1. Launch App. 2. Press "Play" to start stream. 3. Press Windows Home button. 4. Stream cuts out after a few seconds. 5. Return the backgrounded app to the foreground. 6. Stream continues. According to the documentation, allowBackground should allow the audio stream to continue playing even when the app is backgrounded. Tested on: Windows 10 Pro Windows Phone 10.0 & 8.1 (Microsoft Lumia 640 LTE) Appc Studio: 4.6.0.201605030516 Ti SDK: 5.3.0.v20160509143032 Appc NPM: 4.2.5-5 Appc Core: 5.3.0-44 Node: v4.4.4
  9. Harry Bryant 2016-05-17

    *Reopening ticket* as allowBackground has no effect on Windows 10 phone.
  10. Kota Iguchi 2016-05-18

    Note: From my observation it seems Windows 10 mobile always immediately "suspends" the app when app goes background, and that behavior is different from Windows Phone 8.1. On WP8.1 app is not always suspended even when it goes background. And when app is explicitly suspended audio will be stopped (from what I saw). FYI you can suspends the app explicitly if you connect it from Visual Studio. Maybe related: [Suspending app from VS with BackgroundMediaPlayer stops audio](https://social.msdn.microsoft.com/Forums/en-US/fd45b867-1413-4544-adf2-84e5dc78fe95/suspending-app-from-vs-with-backgroundmediaplayer-stops-audio?forum=winappswithcsharp)
  11. Gary Mathews 2016-05-18

    The background task seems to be cancelled by a system policy (the BackgroundTaskCancellationReason is SystemPolicy) There are two reasons this could happen: - The number of background audio tasks can be at most 1, at any given time - Due to resource constraints, the system may terminate the background task https://msdn.microsoft.com/en-us/windows/uwp/audio-video-camera/background-audio#system-policies-for-background-audio-task-lifetime
  12. Kota Iguchi 2016-05-19

    Removed 5.3.0 target, seems like it's not a trivial fix because it's due to system policy changes on Windows 10. Further investigation will be needed on how to workaround termination of it.
  13. Kota Iguchi 2016-07-01

    Removed 6.0.0 target. We could close this ticket as "Won't fix" because this is system resource policy changes on Windows 10, but I think it's better to just remove the target for now for further investigation. I will update the API docs to address this limitation soon.

JSON Source