美文网首页
音频 音效播放AVFoundation

音频 音效播放AVFoundation

作者: 懂妹儿 | 来源:发表于2016-10-24 11:24 被阅读0次

    音频主要有两种,俗称大小音乐。短的音效,长的音乐.看大牛学习的,勿喷,毕竟小白

    #import//音效(短),音频(时间长)

    ```

    //创建soundID

    ```

    SystemSoundID sound = 0;

    sound = [_soudIDs[name] unsignedIntValue];

    // 生成soundID

    if (sound==0) {

    //url

    CFURLRef ref = (__bridge CFURLRef)([[NSBundle mainBundle]URLForResource:name withExtension:nil]);

    AudioServicesCreateSystemSoundID(ref, &sound);

    //save

    [_soudIDs setValue:@(sound) forKey:name];

    }

    //play

    AudioServicesPlaySystemSound(sound);

    //    AudioServicesPlayAlertSound(sound);//振动效果

    //音乐

    if (player==nil) {

    //

    if (musicName==nil) {

    return;

    }

    NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:musicName withExtension:nil];

    player = [[AVAudioPlayer alloc]initWithContentsOfURL:fileUrl error:nil];

    // 保存到字典中

    [_players setObject:player forKey:musicName];

    // 准备播放,提前加载

    [player prepareToPlay];

    }

    [player play];

    下载使用 https://github.com/dong1993/avfoundation 

    相关文章

      网友评论

          本文标题:音频 音效播放AVFoundation

          本文链接:https://www.haomeiwen.com/subject/cnfluttx.html