Latest 0.1.4
Homepage https://github.com/viki-org/VKVideoPlayer
License Apache License, Version 2.0
Platforms ios 5.0, requires ARC
Dependencies DTCoreText, CocoaLumberjack, VKFoundation
Frameworks QuartzCore, MediaPlayer, AVFoundation
Authors , ,

VKVideoPlayer

VKVideoPlayer is the same battle tested video player used in our Viki iOS App enjoyed by millions of users all around the world.

Read The Intro on Our Engineering Blog

Some of the advance features are:

  • Fully customizable UI
  • No full screen restrictions (have it any size and position you would like!)
  • Display subtitles (SRT supported out of the box)
  • Customize subtitles (use CSS for styling courtesy of DTCoreText)
  • Supports HTTP Live streaming
  • Orientation change support (even when orientation lock is enabled)
  • Bulletproof event machine to easily integrate features like video ads
  • Lots of delegate callbacks for your own logging requirements

Usage

To run the Demo project; clone the repo, and run pod install from the VKVideoPlayer directory first.
After installed pod, open VKVideoPlayer.xcworkspace in Xcode to run Demo Application.

Installation

VKVideoPlayer is available through CocoaPods, to install
it simply add the following line to your Podfile:

pod "VKVideoPlayer", "~> 0.1.1"

Getting Start

Simple way to play Http Live Streaming contents.

VKVideoPlayerViewController *viewController = [[VKVideoPlayerViewController alloc] init];
[self presentModalViewController:viewController animated:YES];
[viewController playVideoWithStreamURL:[NSURL URLWithString:@"http://content.viki.com/test_ios/ios_240.m3u8"]];

Customize

Video Player

It is able to use customized video player view.

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

Also VKVideoPlayerView has simple way for additional control.

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

Sample

// Display newButton when screen is landscape mode.
[self.player.view addSubviewForControl:newButton toView:self.player.view forOrientation:UIInterfaceOrientationMaskLandscape]

To cofigure VKVideoPlayer, there are some properties.

@property (nonatomic, assign) BOOL forceRotate;

This property can change behavior of orientation. If UIViewController has only Portrait mode, but it can rotate to Landscape when set it YES.

@property (nonatomic, assign) CGRect portraitFrame;

This property is used when rotate to Portrait by forceRotate. Video player view will be this frame size.

@property (nonatomic, assign) CGRect landscapeFrame;

This property is used when rotate to Landscape by forceRotate. Video player view will be this frame size.

Subtitles

To customize subtitles, there are some way.
To change font size, use VKSharedUtility. There are 3 values.

// value accepts @0, @1, @2 or @3;
// @0 : Tiny
// @1 : Medium
// @2 : Large
// @3 : Huge
[VKSharedUtility setValue:@1 forKey:kVKSettingsSubtitleSizeKey];

Or you can override following method to customize caption style.

- (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;
}

Delegate methods

VKVideoPlayer has a delegate protocol VKVideoPlayerDelegate.
You can use it for your application’s logging or other controls.
There are all @optional.

- (BOOL)shouldVideoPlayer:(VKVideoPlayer*)videoPlayer changeStateTo:(VKVideoPlayerState)toState;

This method is called before changing state. You can prevent changing state of video player if you return NO.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willChangeStateTo:(VKVideoPlayerState)toState;

This method is before changing state. also before -shouldVideoPlayer:changeStateTo:.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeStateFrom:(VKVideoPlayerState)fromState;

This method is called after changing state.

- (BOOL)shouldVideoPlayer:(VKVideoPlayer*)videoPlayer startVideo:(id<VKVideoPlayerTrackProtocol>)track;

This method is called before loading video. You can prevent before it makes traffic if video shouldn’t play.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willStartVideo:(id<VKVideoPlayerTrackProtocol>)track;

This method is called before starting video. You cannot stop video here.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didStartVideo:(id<VKVideoPlayerTrackProtocol>)track;

This method is called after starting video.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didPlayFrame:(id<VKVideoPlayerTrackProtocol>)track time:(NSTimeInterval)time lastTime:(NSTimeInterval)lastTime;

This method is called every second during playing video.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didPlayToEnd:(id<VKVideoPlayerTrackProtocol>)track;

This method is called finished to play video. You can start to play next video here.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didControlByEvent:(VKVideoPlayerControlEvent)event;

This method is called when user did some actions.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeSubtitleFrom:(NSString*)fronLang to:(NSString*)toLang;

This method is called when user changed bottom caption language.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willChangeOrientationTo:(UIInterfaceOrientation)orientation;

This method is called before rotating animation.

- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeOrientationFrom:(UIInterfaceOrientation)orientation;

This method is called after rotating animation.

- (void)handleErrorCode:(VKVideoPlayerErrorCode)errorCode track:(id<VKVideoPlayerTrackProtocol>)track customMessage:(NSString*)customMessage;

This method is called when ocurred an error.

Available Subtitle Formats

  • SRT

Requirements

iOS 5.0 or later

License

VKVideoPlayer is licensed under the Apache License, Version 2.0. See the LICENSE file for more info.

Latest podspec

{
    "name": "VKVideoPlayer",
    "version": "0.1.4",
    "summary": "VKVideoPlayer is customizable video player component that is able to play mp4, hls videos and display subtitles.",
    "description": "                    * Fully customizable UIn                    * No full screen restrictions (have it any size and position you would like!)n                    * Display subtitles (SRT supported out of the box)n                    * Customize subtitles (use CSS for styling courtesy of DTCoreText)n                    * Supports HTTP Live Streaming protocoln                    * Orientation change support (even when orientation lock is enabled)n                    * Bulletproof event machine to easily integrate features like video adsn                    * Lots of delegate callbacks for your own logging requirementsn",
    "homepage": "https://github.com/viki-org/VKVideoPlayer",
    "screenshots": "https://camo.githubusercontent.com/4258638f03f72effdd2e540b359bab11287fe289/687474703a2f2f656e67696e656572696e672e76696b692e636f6d2f696d616765732f626c6f672f766964656f5f706c617965725f72756e6e696e675f6d616e2e6a7067",
    "license": {
        "type": "Apache License, Version 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "Jarrold Ong": "[email protected]",
        "Jonathan Ong": "[email protected]",
        "Keisuke Matsuo": "[email protected]"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/viki-org/VKVideoPlayer.git",
        "tag": "0.1.4"
    },
    "source_files": "Classes/ios/*.{h,m}",
    "ios": {
        "exclude_files": "Classes/osx"
    },
    "osx": {
        "exclude_files": "Classes/ios"
    },
    "public_header_files": "Classes/**/*.h",
    "resources": [
        "Assets/*.png",
        "Classes/ios/*.{xib}"
    ],
    "frameworks": [
        "QuartzCore",
        "MediaPlayer",
        "AVFoundation"
    ],
    "requires_arc": true,
    "dependencies": {
        "DTCoreText": [
            "~> 1.6.11"
        ],
        "CocoaLumberjack": [
            "~> 1.7.0"
        ],
        "VKFoundation": [
            "0.1.1"
        ]
    }
}

Pin It on Pinterest

Share This