<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ### 錄音功能實現 引入頭文件 ``` #import <AVFoundation/AVFoundation.h> #import <AVKit/AVKit.h> ``` 在 **@interface** ViewController ()中添加錄音類 ``` //錄音 @property (strong, nonatomic) AVAudioRecorder \*recorder; ``` 在 @implementation ViewController下添加懶加載 ``` //懶加載 - (AVAudioRecorder *) recorder { if (!_recorder) { //路徑 NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/record"]; //錄音設置 NSMutableDictionary *settingDic = [[NSMutableDictionary alloc] init]; //采樣率 [settingDic setValue:\[NSNumber numberWithInt:44100] forKey:AVSampleRateKey]; //錄音格式 [settingDic setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; //錄音通道 [settingDic setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey]; //錄音質量 [settingDic setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey]; _recorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:path] settings:settingDic error:nil]; [_recorder prepareToRecord]; } return _recorder; } ``` 然后在關聯按鈕函數里實現錄音功能: ``` - (IBAction)record:(UIButton *)sender { if (sender.isSelected == NO) { //開啟錄音 [self.recorder record]; sender.selected = YES; } else { //停止錄音 [self.recorder stop]; sender.selected = NO; } } ``` ### 播放音頻 音頻文件的路徑 可以是本地或是網址 在 **@interface** ViewController ()中添加播放音頻類 ``` @property (strong, nonatomic)AVAudioPlayer *player; ``` 在 @implementation ViewController下添加懶加載 ``` - (AVAudioPlayer *)player{ if (!_player) { //音頻文件路徑 NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/record"]; //可以直接播放的本地音頻路徑 //NSString *path = [[NSBundle mainBundle]pathForResource:@"蓮蓮花"ofType:@"mp3"]; //播放器對象 _player = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil]; [_player prepareToPlay]; } return _player; } ``` 然后再player按鈕關聯的函數里實現播放功能: ``` - (IBAction)play:(UIButton *)sender { //播放 [self.player play]; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看