電話から MP3 を送信する:
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [pathArray objectAtIndex:0];
NSString *yourSoundPath = [documentsDirectory stringByAppendingPathComponent:@"MyMusic.mp3"];
NSURL *url = [NSURL fileURLWithPath:yourSoundPath isDirectory:NO];
[self.session transferFile:url metadata:nil];
時計でファイルを受信して再生しようとした方法:
-(void)session:(WCSession *)session didReceiveFile:(WCSessionFile *)file {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"URL%@" , file.fileURL.filePathURL);
NSDictionary *options = @{
WKMediaPlayerControllerOptionsAutoplayKey : @YES
};
[self presentMediaPlayerControllerWithURL:file.fileURL.filePathURL options:options completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * __nullable error) {
if (!didPlayToEnd) {
NSLog(@"The player did not play all the way to the end. The player only played until time - %.2f.", endTime);
}
if (error) {
NSLog(@"There was an error with playback: %@.", error);
}
}];
});
}
ファイルの URL は次のとおりです。
file:///var/mobile/Containers/Data/PluginKitPlugin/-------/Documents/Inbox/com.apple.watchconnectivity/------/Files/----/MyMusic.mp3
これはエラーです:
再生でエラーが発生しました: エラー ドメイン=com.apple.watchkit.errors コード=4 「要求された URL はこのサーバーで見つかりませんでした。」UserInfo={NSUnderlyingError=0x16d4fa10 {エラー ドメイン=NSPOSIXErrorDomain Code=2 "そのようなファイルまたはディレクトリはありません"}, NSLocalizedDescription=要求された URL がこのサーバーで見つかりませんでした。}.
このファイルを watchOS 2 で再生するにはどうすればよいですか?