Search code examples
xcodeipadavfoundationavplayer

Play multiple Audio Files with AVPlayer


I'm trying to play multiple sounds at the same time.

The approach initially I've taken was to create several players , but it seems wrong one.

What's the best way to play several audio files at the same time.

Is it through making them AVAssets, but in this case how would I stop and play them whenever I want.

Really appreciate your help.

The reason I need AVPlayer is to fetch sounds from the iPod Library.

I finally got an answer from TechSupport of Apple Dev Team and it seems I'm on the right track when I decided to use several AVPlayer.


Solution

  • For every sound you want to make make a new AVPlayer.

    NSURL *url = [NSURL URLWithString:pathToYourFile];
    AVPlayer *audioPlayer = [[AVPlayer alloc] initWithURL:url];
    [audioPlayer play];