0

私のアプリでは、AVAudioPlayerを使用してオーディオを再生します。それはすべて大丈夫で、数分間は正常に動作しますが、ある時点でクラッシュし、これが私のコードとコンソール出力ですが、問題を解決する方法がわかりません...

私はこのコードを持っています:

- (void) viewDidLoad{
    [super viewDidLoad];

    soundID = [[AVAudioPlayer alloc]init];
}

- (void)playAudioReturnLettera{
    NSString *path = [NSString stringWithFormat:@"%@/%@",
                      [[NSBundle mainBundle] resourcePath],
                      @"returnObject.mp3"];
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
    [soundID initWithContentsOfURL:filePath error:nil];
    soundID.delegate = self; //<-- here I have the problem (Thread 1)
    [soundID prepareToPlay]; 
    [soundID play];

}

これはコンソールの出力です:

10:13:07.639 <0x3fbdad98> shm_open failed: "AppleAudioQueue.100.778" (23) flags=0x2 errno=24

2012-04-26 10:13:07.643 Game[155:418b] 10:13:07.643 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.779" (23) flags=0x2 errno=24

2012-04-26 10:13:07.655 Game[155:418f] 10:13:07.655 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.780" (23) flags=0x2 errno=24

2012-04-26 10:13:07.664 Game[155:4193] 10:13:07.664 <0x2fffd000> shm_open failed: 
"AppleAudioQueue.100.781" (23) flags=0x2 errno=24

2012-04-26 10:13:07.680 Game[155:4197] 10:13:07.680 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.782" (23) flags=0x2 errno=24

2012-04-26 10:13:07.696 Game[155:419b] 10:13:07.696 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.783" (23) flags=0x2 errno=24

2012-04-26 10:13:07.711 Game[155:419f] 10:13:07.711 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.784" (23) flags=0x2 errno=24

2012-04-26 10:13:07.727 Game[155:41a3] 10:13:07.727 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.785" (23) flags=0x2 errno=24

2012-04-26 10:13:07.744 Game[155:41a7] 10:13:07.744 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.786" (23) flags=0x2 errno=24

2012-04-26 10:13:07.759 Game[155:41ab] 10:13:07.759 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.787" (23) flags=0x2 errno=24

2012-04-26 10:13:07.775 Game[155:41af] 10:13:07.775 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.788" (23) flags=0x2 errno=24

2012-04-26 10:13:07.792 Game[155:41b3] 10:13:07.793 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.789" (23) flags=0x2 errno=24

2012-04-26 10:13:07.807 Game[155:41b7] 10:13:07.807 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.790" (23) flags=0x2 errno=24

2012-04-26 10:13:07.823 Game[155:41bb] 10:13:07.823 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.791" (23) flags=0x2 errno=24

2012-04-26 10:13:07.840 Game[155:41bf] 10:13:07.841 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.792" (23) flags=0x2 errno=24

2012-04-26 10:13:07.857 Game[155:41c3] 10:13:07.857 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.793" (23) flags=0x2 errno=24

2012-04-26 10:13:07.873 Game[155:41c7] 10:13:07.873 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.794" (23) flags=0x2 errno=24

2012-04-26 10:13:07.890 Game[155:41cb] 10:13:07.890 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.795" (23) flags=0x2 errno=24

2012-04-26 10:13:07.905 Game[155:41cf] 10:13:07.906 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.796" (23) flags=0x2 errno=24

2012-04-26 10:13:07.921 Game[155:41d3] 10:13:07.921 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.797" (23) flags=0x2 errno=24

2012-04-26 10:13:07.938 Game[155:41d7] 10:13:07.938 <0x2fffd000> shm_open failed: "AppleAudioQueue.100.798" (23) flags=0x2 errno=24

2012-04-26 10:13:10.478 Game[155:707] *** -[AVAudioPlayer setDelegate:]: message sent to deallocated instance 0x546bb50
4

2 に答える 2

1

メソッドが返すオブジェクトを保存せずinitWithContentsOfURL:error:に、すでに初期化されたオブジェクト( )に対して初期化メソッド()を呼び出しています。soundID

割り当てと初期化を一緒に維持する(そして一度だけ初期化する)ことをお勧めします。そうすれば、コードは次のようになります。

- (void) viewDidLoad{

    [super viewDidLoad];

    NSString *path = [NSString stringWithFormat:@"%@/%@",
                     [[NSBundle mainBundle] resourcePath],
                     @"returnObject.mp3"];
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
    soundID = [[AVAudioPlayer alloc] initWithContentsOfURL:filePath error:nil];
    soundID.delegate = self;
}

- (void)playAudioReturnLettera{
    [soundID prepareToPlay]; 
    [soundID play];
}
于 2012-04-26T09:02:43.373 に答える
0

このコードを試してください。これはあなたのために働くでしょう。AVAudioPlayerDelegate.hファイルに追加することを忘れないでください。

- (void) viewDidLoad{

    [super viewDidLoad];

}

- (void)playAudioReturnLettera{
    NSString *path = [NSString stringWithFormat:@"%@/%@",
                     [[NSBundle mainBundle] resourcePath],
                     @"returnObject.mp3"];
    NSURL *filePath = [NSURL fileURLWithPath:path];
    soundID = [[AVAudioPlayer alloc] initWithContentsOfURL:filePath error:nil];
    soundID.delegate = self;
    [soundID play];
}
-(void)audioPlayerDidFinishPlaying: (AVAudioPlayer *)player successfully:(BOOL)flag{
    NSLog(@"Audio Player Successfully played");
}

-(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error{

    NSLog(@"Decode Error occurred");
}
于 2012-04-26T13:41:17.593 に答える