0
나는 ViewController
을 UITableViewController
에서 불러와 노래 이름과 색인을 전달합니다. 처음으로 노래를 재생하지만, tableView
으로 돌아가서 다른 노래를 클릭하면 두 노래가 동시에 재생됩니다.여러 노래를 동시에 재생하는 AVAudioPlayer?
는 .h
파일에서 나는 .m
파일에서 AVAudioPlayer
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
을 사용 :
- (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];
}
I 재생되어 있는지 확인해야 이것을 시도했습니다. 작동하지 않습니다. – iTag
당신은 글을 써야합니다. e this 메소드 상단에서 -> "self.audioPlayer = [[AVAudioPlayer alloc]"이전에 –