從手機發送一個MP3:播放音頻文件WatchKit OS2
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);
}
}];
});
}
此文件的網址:
file:///var/mobile/Containers/Data/PluginKitPlugin/-------/Documents/Inbox/com.apple.watchconnectivity/------/Files/----/MyMusic.mp3
這是錯誤:
There was an error with playback: Error Domain=com.apple.watchkit.errors Code=4 "The requested URL was not found on this server." UserInfo={NSUnderlyingError=0x16d4fa10 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}, NSLocalizedDescription=The requested URL was not found on this server.}.
如何在watchOS 2中播放此文件?
我沒有意識到,共享應用程序組在手錶上是必要的。感謝您的教育回答! –