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

  • 相关阅读:
    Bypass WAF
    一种简单的hook方法--LD_PRELOAD变量
    Linux C:access()时间条件竞争漏洞
    环境变量法提权
    sudo-tcpdump提权法
    asynico转载
    pychar 2020.1.2激活
    临时mysql 链接池
    python pip 使用阿里云镜像安装库
    zookeeper kafaka 临时保存
  • 原文地址:https://www.cnblogs.com/zander/p/2640609.html
Copyright © 2011-2022 走看看