Play a short sound in iOS

前端 未结 13 863
悲哀的现实
悲哀的现实 2020-11-27 10:23

I guess I could use AVAudioPlayer to play a sound, however, what I need is to just play a short sound and I don\'t need any loops or fine-grained control over t

13条回答
  •  无人及你
    2020-11-27 11:05

    Recently, I used this code to play short mp3 audio which worked fine:-

    Declare this below the @implementation

    NSString *path;
    
    NSURL *url;
    
    //where you are about to add sound 
    
    path =[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"quotes_%d",soundTags] ofType:@"mp3"];
    
        url = [NSURL fileURLWithPath:path];
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
        [player setVolume:1.0];
        [player play];
    
    //just add AVFoundation framework
    

提交回复
热议问题