简体   繁体   中英

AVAudioPlayer hitch before playing

I've an AVAudioPlayer with a MP3-file. But before playing, you'll hear a hitch. This is my code:

NSString *geluid = [NSString stringWithFormat:@"RG_%@", nummer];

    NSString *path = [[NSBundle mainBundle] pathForResource:geluid ofType:@"mp3"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

    theAudio.delegate=self;
    [theAudio prepareToPlay];
    [theAudio play];

    NSURL *url = [NSURL fileURLWithPath:path];
    avplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    [avplayer prepareToPlay];
    [avplayer play];

For example: You hear "Ssstop here", in stead off "Stop here". Please help me to fix it.

Is this code running two AVAudioPlayer instances at the same time ? Why are you using both avplayer and theAudio ? From looking at it it looks like you should get rid of one of them...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM