0

次の方法でオンとオフを切り替えることができるオーディオを再生しています

IBAction//オーディオを再生

NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/Apptrack.mp3"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;

//Initialize our player pointing to the path to our resource
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
          [NSURL fileURLWithPath:resourcePath] error:&err];

if( err ){

    NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
    //set our delegate and begin playback
    player.delegate = self;
    [player play];
    player.numberOfLoops = -1; //(for continuous loop use -1, or any number for number of loops)
    player.currentTime = 1;
    player.volume = .5;

}

サウンドプレーヤーをオフにするIBAction://オーディオを停止します

 [player stop];

別のビューコントローラーを押して再び戻ると、ボタンが機能しなくなり、オーディオが停止し、常に実行されます(ループの長さは約3分です)。それで、私はこれを上記のコードに追加してみました:

 if ([self.player isPlaying] == YES) {
     [self.player stop];
    } else {
     [self.player play];
    }

それでも何もありません。プログラミングの経験が豊富な人が、私が間違っていることの方向に私を向けることができるでしょうか。

4

1 に答える 1

0

[player stop];次のビューコントローラに押すボタンのIBActionに追加した回避策を見つけました

于 2012-07-09T20:28:31.973 に答える