我正在创建一个手表应用程序,它记录一个音频并播放该音频。录制的音频保存在应用程序组中,我使用了下面的代码来播放音频。
- (void)playAudio
{
// Playing the audio from the url using the default controller
[self presentMediaPlayerControllerWithURL:self.audioFileURL options:@{WKMediaPlayerControllerOptionsAutoplayKey : @YES} completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * _Nullable error) {
NSLog(@"Error = %@",error);
}];
}不幸的是,我得到了下面的错误和球员控制器立即被解雇。
错误Domain=com.apple.watchkit.errors Code=4“操作无法完成”UserInfo={NSLocalizedFailureReason=An未知错误发生(1),NSUnderlyingError=0x16daa810 {NSLocalizedFailureReason=An Domain=NSPOSIXErrorDomain Code=1“不允许操作”},NSLocalizedDescription=The操作无法完成}。
然后我从苹果WatchOS开发者库下载了一个示例项目(WatchOS),但他们也有同样的问题。我不知道为什么这在苹果的示例代码中也不起作用:
发布于 2015-10-30 11:10:17
最后,我发现数据没有写入url路径。还应该在以下路径中编写:Library/Caches/filename.扩展名这里是一个示例代码,它可能会对某人有所帮助。
- (void)writeAudioToAppGroupsWithData:(NSData *)audioData
{
// Writing the audio data to the App Groups
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:APP_GROUP_IDENTIFIER];
containerURL = [containerURL URLByAppendingPathComponent:[NSString stringWithFormat:DIRECTORY_PATH]];
[audioData writeToURL:containerURL atomically:YES];
}在本例中,请确保您的DIRECTORY_PATH是Library/Caches/filename.extension.库/缓存/Audio.mp3
https://stackoverflow.com/questions/33413922
复制相似问题