0
我打電話這個ViewController
從另一個UITableViewController
其通過歌曲名稱和index.For的第一次它播放的歌曲,但是當我回到tableView
並單擊另一首歌曲也同時播放兩首歌曲。AVAudioPlayer同時播放多首歌曲?
在.h
文件我用AVAudioPlayer
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
在.m
文件:
- (void)viewDidLoad
{
[super viewDidLoad];
[self sliderValueChanged:volumeSlider];
[self updateTime];
[self playOrPauseSound:nil];
volumeSlider.value=0.5;
count=songArray.count;
[self setupAVPlayerForURL:songIndex];
_audioPlayer.delegate=self;
}
-(void) setupAVPlayerForURL: (int) url {
NSString *songname=[NSString stringWithFormat:@"%@",songArray[songIndex]];
songTitle.text=songname;
NSString* saveFileName = songname;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:saveFileName];
NSURL *url1 = [[NSURL alloc] initFileURLWithPath: path];
self.audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:NULL];
[self.audioPlayer play];
self.seekBarSlider.minimumValue = 0.0f;
self.seekBarSlider.maximumValue = self.audioPlayer.duration;
[self updateTime];
self.isPlaying=YES;
_audioPlayer.delegate=self;
[_audioPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
}
我試過這不起作用 – iTag
你必須寫信e在您的方法的頂部 - >「之前」self.audioPlayer = [[AVAudioPlayer alloc]「 –