视频播放
来源:互联网 发布:影视播放源码 编辑:程序博客网 时间:2024/05/01 22:05
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>//播放
@interface ViewController ()
- (IBAction)btnclick:(id)sender;
@property (nonatomic,strong) MPMoviePlayerViewController *playVc;
@property (nonatomic,strong) MPMoviePlayerController *player;
- (IBAction)btnNoViewClick:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
NSString *path = [[NSBundlemainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4"ofType:nil];
NSURL *url = [NSURLfileURLWithPath:path];
//无界面
MPMoviePlayerController *player = [[MPMoviePlayerControlleralloc]initWithContentURL:url];
self.player = player;
// 第三方或者下载demo 封装 自定义控制按钮
player.controlStyle =MPMovieControlStyleNone;
[self.viewaddSubview:player.view];
player.view.translatesAutoresizingMaskIntoConstraints =NO;
self.view.translatesAutoresizingMaskIntoConstraints =NO;
//自动布局约束
NSArray *consH = [NSLayoutConstraintconstraintsWithVisualFormat:@"H:|-0-[playerView]-0-|"options:0metrics:nilviews:@{@"playerView" : player.view}];
NSArray *consV = [NSLayoutConstraintconstraintsWithVisualFormat:@"V:|-70-[playerView]-0-|"options:0metrics:nilviews:@{@"playerView" : player.view}];
[self.viewaddConstraints:consH];
[self.viewaddConstraints:consV];
}
- (void)test
{
//有界面的
NSString *path = [[NSBundlemainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4"ofType:nil];
NSURL *url = [NSURLfileURLWithPath:path];
MPMoviePlayerViewController *playVc = [[MPMoviePlayerViewControlleralloc]initWithContentURL:url];
self.playVc = playVc;
//有界面 展示界面
}
- (IBAction)btnclick:(id)sender {
[selfpresentViewController:self.playVcanimated:YEScompletion:nil];
}
- (IBAction)btnNoViewClick:(id)sender {
[self.playerprepareToPlay];
[self.playerplay];
//[self.player pause];
}
@end
#import "ViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()<AVPlayerViewControllerDelegate>
- (IBAction)playClick:(id)sender;
@property (nonatomic,strong) AVPlayerViewController *playerVc;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
NSString *path = [[NSBundlemainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4"ofType:nil];
NSURL *url = [NSURLfileURLWithPath:path];
AVPlayerViewController *playerVc = [[AVPlayerViewControlleralloc]init];
self.playerVc = playerVc;
playerVc.player = [[AVPlayeralloc]initWithURL:url];
playerVc.delegate = self;
//画中画
//1.开启 2.属性支持画中画 3.iPad air2之后的新的
playerVc.allowsPictureInPicturePlayback =YES;
}
- (IBAction)playClick:(id)sender {
[selfpresentViewController:self.playerVcanimated:YEScompletion:nil];
//[self.playerVc.player play];
}
/*!
@method playerViewControllerWillStartPictureInPicture:
@param playerViewController
The player view controller.
@abstract Delegate can implement this method to be notified when Picture in Picture will start.
*/
- (void)playerViewControllerWillStartPictureInPicture:(AVPlayerViewController *)playerViewController;{
NSLog(@"playerViewControllerWillStartPictureInPicture");
}
/*!
@method playerViewControllerDidStartPictureInPicture:
@param playerViewController
The player view controller.
@abstract Delegate can implement this method to be notified when Picture in Picture did start.
*/
- (void)playerViewControllerDidStartPictureInPicture:(AVPlayerViewController *)playerViewController;{
NSLog(@"playerViewControllerDidStartPictureInPicture");
}
/*!
@method playerViewController:failedToStartPictureInPictureWithError:
@param playerViewController
The player view controller.
@param error
An error describing why it failed.
@abstract Delegate can implement this method to be notified when Picture in Picture failed to start.
*/
- (void)playerViewController:(AVPlayerViewController *)playerViewController failedToStartPictureInPictureWithError:(NSError *)error;{
NSLog(@"failedToStartPictureInPictureWithError");
}
/*!
@method playerViewControllerWillStopPictureInPicture:
@param playerViewController
The player view controller.
@abstract Delegate can implement this method to be notified when Picture in Picture will stop.
*/
- (void)playerViewControllerWillStopPictureInPicture:(AVPlayerViewController *)playerViewController;{
NSLog(@"playerViewControllerWillStopPictureInPicture");
}
/*!
@method playerViewControllerDidStopPictureInPicture:
@param playerViewController
The player view controller.
@abstract Delegate can implement this method to be notified when Picture in Picture did stop.
*/
- (void)playerViewControllerDidStopPictureInPicture:(AVPlayerViewController *)playerViewController;{
NSLog(@"playerViewControllerDidStopPictureInPicture");
}
/*!
@method playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart:
@param playerViewController
The player view controller.
@abstract Delegate can implement this method and return NO to prevent player view controller from automatically being dismissed when Picture in Picture starts.
*/
- (BOOL)playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart:(AVPlayerViewController *)playerViewController;{
return NO;
}
/*!
@method playerViewController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:
@param playerViewController
The player view controller.
@param completionHandler
The completion handler the delegate needs to call after restore.
@abstract Delegate can implement this method to restore the user interface before Picture in Picture stops.
*/
- (void)playerViewController:(AVPlayerViewController *)playerViewController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler;{
completionHandler(YES);
}
@end
- 视频播放
- 视频播放
- 播放视频
- 视频播放
- 播放视频
- 播放视频
- 播放视频
- 播放视频
- 播放视频
- 视频播放
- 视频播放
- 播放视频
- 视频播放
- 视频播放
- 播放视频
- 视频播放
- 视频播放
- 播放视频
- Public key for apr-util-1.2.7-11.el5_5.1.i386.rpm is not installed
- linux字符设备驱动模型
- @dynamic
- 7、DOM解析
- Reverse Vowels of a String -- 颠倒字符串中的元音
- 视频播放
- ListView中convertView和ViewHolder的工作原理
- nagios常见错误
- <github for windows(win10)客户端安装教程>
- 使用三种循环计算10的阶乘
- springMVC(4)------RequestParam注解绑定请求参数
- 苹果安装tomcat方法
- ffmpeg的编译
- malloc和new的区别