IOS視頻播放器VKVideoPlayer

來源:互聯網
上載者:User

標籤:ios

VKVideoPlayer 是一個在 Viki iOS 應用裡使用的視頻播放器。

主要特性:

完全可定製的 UI
任何大小乃至全屏
支援字幕顯示
可定製的字幕顯示風格
支援 HTTP 直播流
支援螢幕方向調整
Bulletproof event machine to easily integrate features like video ads
Lots of delegate callbacks for your own logging requirements
VKVideoPlayer是一個經過嚴格測試的Viki視頻播放器,是一個可以處理視頻播放的所有技術細節的簡單外掛程式。預設情況下,該庫使用AVPlayer和AVPlayerItem類在VKVideoPlayerView上播放視頻。它是通過進入一個實施VKVideoPlayerTrackProtocol協議的跟蹤對象來實現的。預設視頻播放器會建立AVPlayer和AVPlayerItem對象來播放視頻。

具有一些改進功能:完全自訂UI;沒有全屏限制(可設定任意大小);可以顯示字幕(支援SRT)並可自訂;支援HTTP Live Streaming協議;支援方向改變,即使開啟方向鎖定;支援Bulletproof事件機制,可以很容易地整合視頻廣告等功能;可為日誌需求進行delegate callbacks。

iOS視頻播放器VKVideoPlayer

VKVideoPlayer用法教程

播放直播流

VKVideoPlayerViewController *viewController = [[VKVideoPlayerViewController alloc] init];
[self presentModalViewController:viewController animated:YES];
[viewController playVideoWithStreamURL:[NSURL URLWithString:@”http://content.viki.com/test_ios/ios_240.m3u8“]];
常用方法

self.player = [[VKVikiVideoPlayer alloc] initWithVideoPlayerView:[[VKVikiVideoPlayer alloc] init]];
self.player.delegate = self;
[self.view addSubview:self.player]

VKVideoPlayerView有簡單的方法添加到視圖.

  • (void)addSubviewForControl:(UIView *)view;
  • (void)addSubviewForControl:(UIView )view toView:(UIView)parentView;
  • (void)addSubviewForControl:(UIView )view toView:(UIView)parentView forOrientation:(UIInterfaceOrientationMask)orientation;

//展示按鈕
[self.player.view addSubviewForControl:newButton toView:self.player.view forOrientation:UIInterfaceOrientationMaskLandscape];

VKVideoPlayer的屬性.

//這個屬性可以改變的行為取向。如果UIViewController只有Portrait mode,把它設定為YES可以旋轉螢幕。
@property (nonatomic, assign) BOOL forceRotate;

//當你旋轉播放螢幕時,視頻播放器視圖將是這個大小。
@property (nonatomic, assign) CGRect landscapeFrame;
This property is used when rotate to Landscape by forceRotate. Video player view will be this frame size.

關於字母

要自訂字幕,有一些方法。改變字型大小,使用vksharedutility。有3個值。
// value accepts @0, @1, @2 or @3;
// @0 : Tiny
// @1 : Medium
// @2 : Large
// @3 : Huge
[VKSharedUtility setValue:@1 forKey:kVKSettingsSubtitleSizeKey];

//或者你可以重寫下面的方法來自訂標題樣式。

  • (DTCSSStylesheet*)captionStyleSheet:(NSString*)color {
    float fontSize = 1.3f;
    float shadowSize = 1.0f;

switch ([[VKSharedUtility setting:kVKSettingsSubtitleSizeKey] integerValue]) {
case 1:
fontSize = 1.5f;
break;
case 2:
fontSize = 2.0f;
shadowSize = 1.2f;
break;
case 3:
fontSize = 3.5f;
shadowSize = 1.5f;
break;
}

DTCSSStylesheet* stylesheet = [[DTCSSStylesheet alloc] initWithStyleBlock:[NSString stringWithFormat:@”body{\
text-align: center;\
font-size: %fem;\
font-family: Helvetica Neue;\
font-weight: bold;\
color: %@;\
text-shadow: -%fpx -%fpx %fpx #000, %fpx -%fpx %fpx #000, -%fpx %fpx %fpx #000, %fpx %fpx %fpx #000;\
vertical-align: bottom;\
}”, fontSize, color, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize, shadowSize]];
return stylesheet;
}
代理方法

//vkvideoplayer已委託協議vkvideoplayerdelegate。您可以使用它為您的應用程式的日誌記錄或其他控制項。

//這種方法被稱為在改變狀態之前。如果你還沒有,你可以阻止視頻播放器的狀態改變。
- (BOOL)shouldVideoPlayer:(VKVideoPlayer*)videoPlayer changeStateTo:(VKVideoPlayerState)toState;

//這種方法是在改變狀態之前。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willChangeStateTo:(VKVideoPlayerState)toState;

//這種方法被稱為改變狀態。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeStateFrom:(VKVideoPlayerState)fromState;

//此方法在載入視頻之前被調用。如果視頻不應該播放,你可以在它的交通流量之前阻止。
- (BOOL)shouldVideoPlayer:(VKVideoPlayer*)videoPlayer startVideo:(id)track;

//這種方法是在開始視頻之前調用的。你不能在這裡停止視頻。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willStartVideo:(id)track;

//這種方法是在啟動視頻後調用的。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didStartVideo:(id)track;

//在播放視頻時,這種方法被稱為每一秒。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didPlayFrame:(id)track time:(NSTimeInterval)time lastTime:(NSTimeInterval)lastTime;

//這種方法被稱為完成播放視頻。你可以開始播放下一段視頻在這裡。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didPlayToEnd:(id)track;

//這種方法被稱為當使用者做了一些行動。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didControlByEvent:(VKVideoPlayerControlEvent)event;

//這種方法被稱為當使用者更改的底部標題語言。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeSubtitleFrom:(NSString*)fronLang to:(NSString*)toLang;

//這種方法被稱為旋轉動畫之前。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willChangeOrientationTo:(UIInterfaceOrientation)orientation;

//這種方法被稱為旋轉動畫後。
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeOrientationFrom:(UIInterfaceOrientation)orientation;

//調用此方法時發生錯誤。
- (void)handleErrorCode:(VKVideoPlayerErrorCode)errorCode track:(id)track customMessage:(NSString*)customMessage;

代碼

本文由51ios原創,轉載請註明轉載自http://www.51ios.net/thirdlibs/5692.html

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

IOS視頻播放器VKVideoPlayer

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.