6.19 Media 音频&视频
来源:互联网 发布:实时黄金价格软件 编辑:程序博客网 时间:2024/04/29 20:08
1,Audio
// 引入相应的框架@import AVFoundation;@interface MusicViewController () <AVAudioPlayerDelegate>@property(strong,nonatomic)AVAudioPlayer *player;
- (void)initlializeDataSource{ //1,创建URL NSURL *url = [[NSBundle mainBundle] URLForResource:@"Release My Soul" withExtension:@"mp3"]; //2,创建player self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; //放入缓存池 [self.player prepareToPlay]; //设置代理 self.player.delegate = self; //设置音量(0-1) self.player.volume = 0.1;}
- (void)initlializeUserInterface{ //按钮1:音效播放 //1,创建BUTTON UIButton *Button = [UIButton buttonWithType:UIButtonTypeSystem]; //2. 设置标题 [Button setTitle:@"音效播放" forState:UIControlStateNormal]; //3. 设置大小 [Button setBounds:CGRectMake(0, 0, 80, 100)]; //4. 设置中心点 [Button setCenter:CGPointMake(100, 200)]; //5. 添加到视图 [self.view addSubview:Button]; // 按钮2:音乐播放 //1. 创建button UIButton *musicButton = [UIButton buttonWithType:UIButtonTypeCustom]; //2. 设置标题 [musicButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [musicButton setTitle:@"音乐播放" forState:UIControlStateNormal]; // 3. 设置大小 [musicButton setBounds:CGRectMake(0, 0, 80, 100)]; // 4. 设置中心点 [musicButton setCenter:CGPointMake(300, 200)]; // 5. 添加到视图 [self.view addSubview:musicButton]; // 6. 添加事件 [Button addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside]; [musicButton addTarget:self action:@selector(handleMusicButtonEvent:) forControlEvents:UIControlEventTouchUpInside];}
- (void)handleButtonEvent:(UIButton *)sender{ //1,获取URL //NSString *path = [[NSBundle mainBundle] pathForResource:@"SystemSound" ofType:@"wav"]; NSURL *url = [[NSBundle mainBundle] URLForResource:@"SystemSound" withExtension:@"wav"]; //2.创建音乐播放ID变量 SystemSoundID systemID = 0; //3. 进行函数调用创建系统音乐ID AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url),&systemID); //4.进行音效播放 AudioServicesPlaySystemSound(systemID);}#pragma mark - AVAudioPlayerDelegate//AVAudioPlayerDelegate- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{// 音乐播放完毕的时候调用该方法}//音乐点击按钮- (void)handleMusicButtonEvent:(UIButton *)sender{ if ([self.player isPlaying]) { [self.player pause]; } else { [self.player play]; }}
2,MediaPlayer
#import "MovieViewController.h"@import MediaPlayer;@interface MovieViewController ()@property (nonatomic, strong) MPMoviePlayerController *play;@property (nonatomic, strong) MPMoviePlayerViewController *playerVC;- (void)initlializeUserInterface;@end
@implementation MovieViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initlializeUserInterface];}- (void)initlializeUserInterface{ // 按钮1:直接播放 // 1. 创建button UIButton *Button = [UIButton buttonWithType:UIButtonTypeSystem]; // 2. 设置标题 [Button setTitle:@"直接播放" forState:UIControlStateNormal]; // 3. 设置大小 [Button setBounds:CGRectMake(0, 0, 80, 100)]; // 4. 设置中心点 [Button setCenter:CGPointMake(200, 500)]; // 5. 添加到视图 [self.view addSubview:Button]; // 按钮2:全屏播放 // 1. 创建button UIButton *musicButton = [UIButton buttonWithType:UIButtonTypeSystem]; // 2. 设置标题 [musicButton setTitle:@"全屏播放" forState:UIControlStateNormal]; // 3. 设置大小 [musicButton setBounds:CGRectMake(0, 0, 80, 100)]; // 4. 设置中心点 [musicButton setCenter:CGPointMake(100, 500)]; // 5. 添加到视图 [self.view addSubview:musicButton]; // 6. 添加事件 [Button addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside]; [musicButton addTarget:self action:@selector(handleMovieButtonEvent:) forControlEvents:UIControlEventTouchUpInside];}//直接播放- (void)handleButtonEvent:(UIButton *)sender{ //1,创建URL NSURL *url = [[NSBundle mainBundle] URLForResource:@"宣传资料" withExtension:@"mp4"]; //2,创建player MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url]; //3,设置player视图 player.view.frame = CGRectMake(0, 20, 375, 667); //4,设置player视图缩放 player.scalingMode = MPMovieScalingModeAspectFit; //5,添加到视图 [self.view addSubview:player.view]; //6,播放plyer [player play]; //7, 对象持有一次,否则无法播放 self.play = player;}//全屏播放- (void)handleMovieButtonEvent:(UIButton *)sender{ //注册通知(当视频播放完毕和用户播放完毕的时候发送通知) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMovieEvent:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; //1,创建URL NSURL *url = [[NSBundle mainBundle] URLForResource:@"宣传资料" withExtension:@"mp4"]; //2,创建playVC self.playerVC = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; //3,推送 [self presentMoviePlayerViewControllerAnimated:self.playerVC];}- (void)handleMovieEvent:(NSNotification *)not{}
0 0
- 6.19 Media 音频&视频
- 第十天 media 视频 音频
- Media Player网页播放音频,视频,图片总汇
- 设置了Media.EXTERNAL_CONTENT_URI却找不到音频/视频的解决方法
- adkill and media download 探测网站中视频、音频真实地址
- HTML5无插件多媒体Media——音频audio与视频video
- Android关于本地多媒体(图片、视频、音频)Media的选择总结
- 音频/视频
- 音频,视频
- Adobe Media Encoder CC 2018 for Mac(视频音频编码软件)附破解补丁 v12.0中文破解版
- Media播放(播放音频,录音等)
- 视频播放器 media player
- html嵌入视频media方法
- android视频播放器Media
- 视频音频处理!
- 页面音频、视频播放
- 音频、视频播放
- ffmpeg播放视频音频
- 记录一个JS
- 编程学习网站
- TCP/IP学习笔记(2)----------IP协议与寻址
- java读取properties配置文件
- 优秀创业者
- 6.19 Media 音频&视频
- 新增activity报错,Could not execute method of the activity
- ElasticSearch集群服务器配置
- Linux gdb调试器用法全面解析
- 导入excel时遇到问题汇总
- JavaScript基础二 JS除错与调试、函数、对象、Array对象
- mongoDB 3.0 安全权限访问控制
- 几本书
- linux epoll模型