-
Notifications
You must be signed in to change notification settings - Fork 5
快速集成
下载金山云播放SDK及VR播放SDK
将播放SDK中framework目录下KSYVRPlayer.framework和VR播放SDK中framework目录下的KSYVRPlayer.framework复制到项目下,选择需要集成的target,在target->Build Phases->Link Binary With Libraries下,将KSYMediaPlayer.framework和KSYVRPlayer.framework添加进去,然后添加另外四个系统库:
- VideoToolbox.framework
- libstdc++.6.tbd 或者libstdc++.6.dylib
- libbz2.tbd 或者 libbz2.dylib
- libz.tbd 或者 libz.dylib
打开需要集成播放视频功能的视图源码,把如下代码复制并粘贴到你将播放视频的位置,例如到播放/停止按钮的方法中。
-
导入头文件
#import <KSYVRPlayer/KSYVRPlayer.h>
-
初始化player
初始化需要几个步骤:-
新建player;
-
设置url;
-
调用initVRMode:dispalyMode:来设置交互和播放模式
-
调用setContainer:view:来设置播放器所在的ViewController和View
-
调用prepareToPlay开始播放。由于已经设置shouldAutoplay为TRUE,则prepare完成后立即开始播放。
KSYMoviePlayerController *player; player = [[KSYVRPlayerController alloc] initWithContentURL:self.url]; player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; player.shouldAutoplay = YES; player.videoDecoderMode = MPMovieVideoDecoderMode_Hardware; player.shouldLoop = YES; [player initVRMode:KSYVRModeInteractiveMotion dispalyMode:KSYVRModeDisplayGlass]; [player setContainer:self view:self.view]; [player prepareToPlay];
说明:与播放SDK有区别的地方在于不要操作player中的view属性,而增加了initVRMode:dispalyMode:和setContainer:view的设置
由于VR播放SDK使用了KSYMediaPlayerController的videoDataBlock属性,所以不能再重新设置该属性,否则会导致VR视频无法渲染 -
-
设置监听
当前SDK提供了多个Notificaton监听,具体可参考消息通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMediaPlaybackIsPreparedToPlayDidChangeNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerPlaybackStateDidChangeNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerPlaybackDidFinishNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerLoadStateDidChangeNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMovieNaturalSizeAvailableNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerFirstVideoFrameRenderedNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerFirstAudioFrameRenderedNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerSuggestReloadNotification) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handlePlayerNotify:) name:(MPMoviePlayerPlaybackStatusNotification) object:nil];
-
销毁播放器
播放器在stop中完成内存释放,new一次KSYMoviePlayerController,需要stop一次。如果两者未配对调用,将引发内存泄露。
[_player stop]