1
votes

I'm trying to achieve a small app where you download an MP4 video in background on the watch, and play once downloaded.

Using WKInterfaceMovie.setVideoURL works well with an https link, but I want to customize the loading UI.

After downloading the video file, I move it to a shared group :

originalURL : Optional("/private/var/mobile/Containers/Data/PluginKitPlugin/FD57E33D-4657-497B-9823-A53D289CDF0B/Library/Caches/com.apple.nsurlsessiond/Downloads/com.test.TestWatchVideo.watchkitapp.watchkitextension/CFNetworkDownload_jKLIrU.tmp")

destinationURL : Optional("/private/var/mobile/Containers/Shared/AppGroup/018DA2BA-EB53-45DA-B3EA-792D4879E601/Library/Caches/SampleVideo_360x240_1mb.mp4")

I'm using removeItemAtURL ( if old file exist ) then copyItemAtURL to move the original file.

=> BUT when trying presentMediaPlayerControllerWithURL , it dismisses before playing video and says :

Error: Error Domain=com.apple.watchkit.errors Code=4 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (1), NSUnderlyingError=0x16d71f20 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}, NSLocalizedDescription=The operation could not be completed}

I've read quite a few threads on StackOverflow and Forums, and none have helped me.

Thanks !

2
I encountered this error because I was attempting to access multiple files in the same block. The fix that worked for me was changing the code structure such that each file url was obtained, then read from, before attempting to get the next file url.Jagveer Singh
Thanks @JagveerSingh, very interesting. I tried to separate the operation in different blocks, but it doesn't seem to help me. In my case, I get the downloaded file in URLSession.didFinishDownloadingToURL, delete old destURL, copy downloaded file into destURL, then presentMediaPlayer with destURL, in the main queue. Do you see any problem in this ?Camille R

2 Answers

1
votes

OK, this was an issue of App Group Capabilities of the WatchKit App; The Application had the good right, the WatchKit App Extension was OK too, but WatchKit App didn't => Operation not permitted only when trying to play video.

This was working on the simulator, no matter you configuration.

0
votes

switch on the App Groups of WatchKit App ...