iPhone で録音したオーディオ ファイルを Watch スピーカーから再生する際に問題が発生しています。
iPhoneからWatchに送信するためのコードを次に示します。
- (void)sendLiveAudioRecordingToWatch
{
NSError *error;
NSFileManager *files = [NSFileManager defaultManager];
NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *record = [docs stringByAppendingPathComponent: @"LiveAudio.m4a"];
NSURL *URL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier: @"group.myCompany.myApp"];
NSURL *outputURL = [URL URLByAppendingPathComponent: @"PhoneToWatch.mp4"];
NSString *path = [NSString stringWithFormat: @"%@", outputURL];
NSLog(@"%@", [NSURL fileURLWithPath: path]);
[files removeItemAtPath: [outputURL path] error: &error];
BOOL fileExists = [files isReadableFileAtPath: record];
if (fileExists)
{
NSLog(@"Live Audio Recording Saved!");
[files copyItemAtPath: record toPath: [outputURL path] error: &error];
if (!error)
{
NSLog(@"Temporary Recording Copied To Group");
BOOL deleteRecord = [files removeItemAtPath: record error: &error];
if (deleteRecord)
{
NSLog(@"Temporary Recording Removed");
if ([WCSession isSupported])
{
WCSession *session = [WCSession defaultSession];
NSLog(@"WCSession isSupported");
[session setDelegate: self];
[session activateSession];
if ([session isReachable])
{
NSLog(@"File Is Being Transferred");
[[WCSession defaultSession] transferFile: outputURL metadata: nil];
}
else
{
NSLog(@"Watch Not Reachable");
}
}
}
else
{
NSLog(@"Failed To Delete Temorary File");
}
}
else
{
NSLog(@"Error Copying Live Audio To Group");
}
}
else
{
NSLog(@"Error Locating Temporary Audio Location");
}
}
iPhoneからWatchで受信するためのコードは次のとおりです。
- (void)session: (WCSession *)session didReceiveFile: (WCSessionFile *)file
{
WKAudioFileAsset *asset = [WKAudioFileAsset assetWithURL: [file fileURL]];
WKAudioFilePlayerItem *playerItem = [WKAudioFilePlayerItem playerItemWithAsset: asset];
WKAudioFilePlayer *player = [WKAudioFilePlayer playerWithPlayerItem: playerItem];
[player play];
}
iOS 9.2 ウォッチOS 2.0
誰かがこれを経験したことがありますか、またはこれを機能させることができましたか?