0
#import "AVFoundation/AVFoundation.h"
は、だから私は問題を抱えて、私は
NSString* soundFilePath = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
NSURL* soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops=-1;
[player play];
(つまり、最初にロードされているものである)私のクラスの初期化メソッドで最初にこのコードを試してみました
しかし、私はスレッドでそれを行うことを決めたよりも、それが、うまくいきませんでした: initメソッドで:
[NSThread detachNewThreadSelector:@selector(playMusic) toTarget:self withObject:nil];
と方法itse lf:
-(void) playMusic {
NSString* soundFilePath = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
NSURL* soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops=-1;
[player play];
}
もちろん* .hファイルで宣言されています。それもうまくいかなかった。
私はplayMusic方式のライン
}
上のファイルが2または3秒間再生し、その後、停止している、デバッグしようとしました。デバッグなしでは再生されません。何が問題ですか?
AVAudioPlayerを、o_O に感謝したクラス – Felix
mgのインスタンス変数にしてください))) – Alexander