zoukankan      html  css  js  c++  java
  • AVFoundation.framwork 及其 部分类的使用

    AVFoundation.framwork框架 :用于播放音频文件

    1. 导入框架 (省略)

    2. 类中引入框架

    #import "AVFoundation/AVFoundation.h"

    3. 声明AVAudioPlayer 声音文件播放类

     NSString *path = [[NSBundle mainBundle] pathForResource:@"chooseplayer"ofType:@"mp3"];

        NSError *error;

        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

            NSURL *musicURL = [NSURL fileURLWithPath:path];

            audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:&error];

            [audioPlayer setVolume:1.0];

            [audioPlayer setNumberOfLoops:0];

            [audioPlayer prepareToPlay];

        }

     4. 播放 声音

        //Play background music

    - (void)playMusic{

        if (![audioPlayer isPlaying]) {

            [audioPlayer play];

        }

    }

    5. 停止播放

     if ([audioPlayerisPlaying]) {

            [audioPlayer stop];

            [audioPlayersetCurrentTime:0];

        }

     

                 ---------- Zander

  • 相关阅读:
    webpack 学习
    文件操作
    关于列表remove的操作和字符串split的操作新领悟
    深浅拷贝和基础类型补充
    小数据池和编码
    字典和集合
    列表和元组
    字符串理论
    递归遍历多层列表
    基本数据类型和操作
  • 原文地址:https://www.cnblogs.com/zander/p/2640609.html
Copyright © 2011-2022 走看看