WatchOS 7 background url tasks not working.

Hello.

I have developed the audio streaming app from watchOS6 to current.
Now I have a critical bug in watchOS7.

Our business process is like that.
  1. fetch the address of audio-content from server.

  2. make the URLAsset with the address.

  3. Play with AVPlayer and URLAsset what I have made.

this process worked very well on watchOS6.
But now, I face the problem fetching the address in background not working perfectly.

I made URLSession with background configuration(Making Background Requests)

Also, sometimes even if there was a correct URL, but cannot play next track.

Please give me any help... thanks.
Answered by sal_from_new_york in 642210022
Hi @jungsufromgwanak-gu,
If I understand you correctly, you are doing the following:
1 - Getting the URL address of your audio asset in the background. This URL address is the content you wish to get via a background URLSession

2 - Using that URL address to then load the audio content into the player in the background as well

3 - Play the audio content.

You are having trouble with 1, 2 or 3? If you're having trouble with 1 that brings up a lot of questions, because you said the URL address is only available for 10 minutes. You cannot schedule a background refresh for less than 15 minutes, so I don't understand how it was working in the first place. Also, even if you could make the scheduling every 10 minutes, how would you synchronize the start of the 10 minutes on the watch with the 10 minutes on the server? As polyphonic pointed out WatchOS could schedule the next background refresh at 10 minutes + n, where n could be several minutes.

Typically I schedule background refresh for the smallest time interval (15 minutes) and then at that point I create a background URL session which then downloads my content. So the best that I can do is get my content approximately every 15 minutes. There's no way to make that time interval 10 minutes. Are you certain that in WatchO 6.x.x the address was being obtained via background URLSession every 10 minutes?
Hi @jungsufromgwanak-gu,
in your Watch Extension's info.plist for "Required Background Modes", do you have these items:
1 - "App plays audio or streams audio/video using AirPlay"
2 - "App downloads content from the network"
3 - "App processes data in the background"?

Also are you debugging in the simulator or on a real device?

Also, if the problem is "fetching the address in background" in the background, then this is not really about HLS.

What is going wrong with fetching the address (URL, I guess you mean)? Is an error being returned?

Why are you fetching the URL in the background? Background network activity may be delayed by the OS, so you don't really know how long it will take to complete. Is there a reason you don't want to do this with a regular URLSession?
to Polyphonic
Thanks to your reply.

The audio content's url can change according to time. This is our service's current business logic.

(In business logic, For example, there are multi access check in other device, streaming right check, fetch next track's url and so on)

So, after finishing the playing of the current track, I have to fetch a next track's audio content url and use the fetched it to make URLAsset. Therefore I cannot use AVQueuePlayer.

There are any solution for in this situation...?
I think there were no problems until watchOS6.

Thanks to your reply.
to salfromnew_york
Thanks to your reply.

Sometimes it can work very well. But sometimes it cannot work also.
I'm very appreciate but it is not a clear solution for me.
to Polyphonic.

The URL for audio contents is only available for just about 10 minute.
So If I move to the next track, I have to fetch a new URL and make a URLAsset with it.
This is our service's privacy policy.

In this situation, I fetched with URLSession in background and working well for audio streaming in watchOS6.
but It doesn't work anymore in watchOS7.

Please give me any help... Thanks.


Accepted Answer
Hi @jungsufromgwanak-gu,
If I understand you correctly, you are doing the following:
1 - Getting the URL address of your audio asset in the background. This URL address is the content you wish to get via a background URLSession

2 - Using that URL address to then load the audio content into the player in the background as well

3 - Play the audio content.

You are having trouble with 1, 2 or 3? If you're having trouble with 1 that brings up a lot of questions, because you said the URL address is only available for 10 minutes. You cannot schedule a background refresh for less than 15 minutes, so I don't understand how it was working in the first place. Also, even if you could make the scheduling every 10 minutes, how would you synchronize the start of the 10 minutes on the watch with the 10 minutes on the server? As polyphonic pointed out WatchOS could schedule the next background refresh at 10 minutes + n, where n could be several minutes.

Typically I schedule background refresh for the smallest time interval (15 minutes) and then at that point I create a background URL session which then downloads my content. So the best that I can do is get my content approximately every 15 minutes. There's no way to make that time interval 10 minutes. Are you certain that in WatchO 6.x.x the address was being obtained via background URLSession every 10 minutes?
WatchOS 7 background url tasks not working.
 
 
Q