presentMediaPlayerControllerWithURL doesn't play non-NSBundle videos in real device

Here's how I use presentMediaPlayerControllerWithURL. I download a video from the internet and save it to ApplicationGroup. It does play on Simulator. However it doesn't play on real device. Anyone know if it's a bug?

p.s.: I can play video from NSBundle on real device.


NSURL * url = [NSURL URLWithString:jsonDic[@"video_url"]];
NSString * fileName = jsonDic[@"file_name"];
NSFileManager * manager = [NSFileManager defaultManager];
NSURL * directoryURL = [manager containerURLForSecurityApplicationGroupIdentifier:@"group.testing"];
NSURL * toURL = [directoryURL URLByAppendingPathComponent:fileName];
NSURLSessionDownloadTask * task = [[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL * __nullable location, NSURLResponse * __nullable response, NSError * __nullable error) {
if (error){
return;
}
[manager copyItemAtURL:location toURL:toURL error:nil];
[self presentMediaPlayerControllerWithURL: toURL
options:@{WKMediaPlayerControllerOptionsAutoplayKey : @YES}
completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * __nullable error) {
if (error){
NSLog(error.localizedDescription);
}
}];
}];
[task resume];

I have exactly same problem. I just can't play saved audio file on real watch device. First time I thought that there are some problems storing a audio file from URL so I tried like below,


- (IBAction)recordingAudioButtonTouched:(id)button
{
        NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
        NSString *path = [[filePaths firstObject] stringByAppendingPathComponent:@"recording.mp4"];
        NSURL *fileUrl = [NSURL fileURLWithPath:path];

        [self presentAudioRecordingControllerWithOutputURL:fileUrl preset:WKAudioRecordingPresetWideBandSpeech maximumDuration:10 actionTitle:@"Send!" completion:^(BOOL didSave, NSError * __nullable error) {
            if (didSave) {
                NSLog(@"yeah");
            } else {
                NSLog(@"nop");
            }
        }];
}

- (IBAction)playAudioButtonTouched:(id)button
{
        NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
        NSString *path = [[filePaths firstObject] stringByAppendingPathComponent:@"recording.mp4"];
       
        NSURL *writeFileUrl = [NSURL fileURLWithPath:path];
        NSDictionary* options = @{WKMediaPlayerControllerOptionsAutoplayKey : @YES};
        [self presentMediaPlayerControllerWithURL:writeFileUrl options:options completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * __nullable error) {
            if (didPlayToEnd) {
               // do something
            }
        }];
}


It works perfactly on simulator but not on the real device. When I touched "playAudioButton", the system media player showed up for a second and just disapper without playing audio file. I still have no idea why I doesn't work. Maybe watchKit 2.0 has some bugs I reckon.

I have same problem too, works at simulator,but error with real watch device,and have error "The operation could not be completed".Did you find anything new?

As I complained here: https://forums.developer.apple.com/message/51425#51425


I believe Apple is not working on the sound. They seem not to allow 3rd parties to play sound. For me, either WKAudioFilePlayer or presentMediaPlayerControllerWithURL does not work on the device.

I see the same error log:


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


Operation not permitted? It can't say anything.... sigh

presentMediaPlayerControllerWithURL doesn't play non-NSBundle videos in real device
 
 
Q