AVAudioPlayer で別のビューからサウンドに到達するのに問題があります。AudioToolbox では完全に機能しますが、AVAudioPlayer では機能しません。これが私のコードです:
.h ファイル:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreText/CoreText.h>
#import "SimpleTableCelldetail.h"
int clicked;
@interface DetailViewController : UIViewController {
AVAudioPlayer *audioPlayer;
IBOutlet UIButton *start;
}
@property (strong, nonatomic) IBOutlet NSString *audioSon;
@end
.m ファイル
-(IBAction)play:(id)sender {
if(clicked == 0) {
clicked = 1;
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:audioSon, [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
[start setTitle:@"Stop" forState:UIControlStateNormal];
}
else {
clicked = 0;
[audioPlayer stop];
[start setTitle:@"Ecouter" forState:UIControlStateNormal];
}
}
このコードを実行すると、ボタンは音を出しません。audioSon の値は「sound01.m4r」です。
ライン交換したら
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:audioSon, [[NSBundle mainBundle] resourcePath]]];
と
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/sound01.m4r", [[NSBundle mainBundle] resourcePath]]];
動作しますが、xcode でエラーが表示されます:
2012-08-01 01:59:44.697 CustomTable[12709:3703] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
何か案が?
ありがとう。