音频播放\录音
来源:互联网 发布:开封教务网络管理系统 编辑:程序博客网 时间:2024/09/21 06:34
#import "ViewController.h"#import <MediaPlayer/MediaPlayer.h>#import <AVFoundation/AVFoundation.h>@interface ViewController ()- (IBAction)playLocation:(UIButton *)sender;- (IBAction)playOnline:(UIButton *)sender;- (IBAction)recordVoice:(UIButton *)sender;- (IBAction)playRecordVoice:(UIButton *)sender;@property (nonatomic,strong) MPMoviePlayerController * player;@property (nonatomic,strong) MPMoviePlayerViewController * mpMoviePlayer;@property (nonatomic,strong) AVAudioRecorder * recorder;@property (nonatomic,strong) NSString * recordVoiceFilePath;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.recordVoiceFilePath = [NSTemporaryDirectory() stringByAppendingString:@"TmpFile.aiff"]; NSLog(@"=======%@",self.recordVoiceFilePath);}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (IBAction)playLocation:(UIButton *)sender { // 本地 [self.player stop]; NSString * path = [[NSBundle mainBundle] pathForResource:@"春天里" ofType:@"mp3"]; NSURL * url = [NSURL fileURLWithPath:path]; self.player = [[MPMoviePlayerController alloc] initWithContentURL:url]; [self.player play]; }- (IBAction)playOnline:(UIButton *)sender { // 在线 [self.player stop]; NSString * path = [NSString stringWithFormat:@"http://202.204.208.83/gangqin/download/music/02/03/02/Track08.mp3"]; NSURL * url = [NSURL URLWithString:path]; self.player = [[MPMoviePlayerController alloc] initWithContentURL:url]; [self.player play];}- (IBAction)recordVoice:(UIButton *)sender { sender.selected = !sender.isSelected; if (sender.selected) { // 录音 [sender setTitle:@"暂停" forState:UIControlStateNormal]; self.recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:self.recordVoiceFilePath] settings:@{AVNumberOfChannelsKey:@2,AVSampleRateKey:@44100,AVLinearPCMBitDepthKey:@32,AVEncoderAudioQualityKey:@(AVAudioQualityMax),AVEncoderBitRateKey:@128000} error:nil]; [self.recorder prepareToRecord]; [self.recorder record]; } else { [sender setTitle:@"录音" forState:UIControlStateNormal]; [self.recorder stop]; } }- (IBAction)playRecordVoice:(UIButton *)sender { sender.selected = !sender.isSelected; if (sender.selected) { // 播放录音 [sender setTitle:@"暂停" forState:UIControlStateNormal]; [self.player stop]; NSURL * url = [NSURL fileURLWithPath:self.recordVoiceFilePath]; self.player = [[MPMoviePlayerController alloc] initWithContentURL:url]; [self.player play]; } else { [sender setTitle:@"播放录音" forState:UIControlStateNormal]; [self.player stop]; }}
1 0
- 录音,播放音频
- 录音/播放音频
- 音频播放\录音
- AVAudioRecord录音,AVAudioPlayer播放音频
- Android 音频 录音与播放
- Media播放(播放音频,录音等)
- 简介录音和播放音频实现
- Android音频操作:录音和播放
- 音频播放,录音,视频播放,拍照,视频录制
- 音频播放、录音、视频播放、拍照、视频录制
- iOS开发 音频播放、录音、视频播放、拍照、视频录制
- iOS 音频播放,录音,视频播放,拍照,视频录制
- iOS 音频播放、录音、视频播放、拍照、视频录制
- iOS开发:音频播放、录音、视频播放、拍照、视频录制
- iOS音频播放、录音、视频播放、拍照、视频录制
- iOS--音频播放、录音、视频播放、拍照、视频录制
- iOS开发--音频播放、录音、视频播放、拍照、视频录制
- iOS 录音Wav 音频 转换 Amr ,Android 播放
- 基于原生javascript的淡入淡出函数封装(兼容IE)
- iOS 10 UIScrollView详解(scrollview自带刷新UIRefreshControl)
- 循环不变式(loop invariant)
- 找出我的GID
- HDU-2015查找最大元素
- 音频播放\录音
- Android 开源项目源码解析 -->Android Universal Image Loader 源码分析(十四)
- Objective-c runnloop
- 2016ACM北京赛区网络赛第三题A simple Job
- BZOJ4245 [ONTAK2015]OR-XOR
- 快速排序解析
- 变量的初始化及默认值
- 自己修改dir 615H1 支持usb 修改固件大小
- 好文:现代浏览器原理详解