-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathVKVideoPlayerViewController.m
125 lines (99 loc) · 3.11 KB
/
VKVideoPlayerViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// Created by Viki.
// Copyright (c) 2014 Viki Inc. All rights reserved.
//
#import "VKVideoPlayerViewController.h"
#import "VKVideoPlayerConfig.h"
#import "VKFoundation.h"
#import "VKVideoPlayerCaptionSRT.h"
#import "VKVideoPlayerAirPlay.h"
#import "VKVideoPlayerSettingsManager.h"
@interface VKVideoPlayerViewController () {
}
@property (assign) BOOL applicationIdleTimerDisabled;
@end
@implementation VKVideoPlayerViewController
- (id)init {
self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
if (self) {
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self initialize];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self initialize];
}
return self;
}
- (void)initialize {
[VKSharedAirplay setup];
}
- (void)dealloc {
[VKSharedAirplay deactivate];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.player = [[VKVideoPlayer alloc] init];
self.player.delegate = self;
self.player.view.frame = self.view.bounds;
self.player.forceRotate = YES;
[self.view addSubview:self.player.view];
if (VKSharedAirplay.isConnected) {
[VKSharedAirplay activate:self.player];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.applicationIdleTimerDisabled = [UIApplication sharedApplication].isIdleTimerDisabled;
[UIApplication sharedApplication].idleTimerDisabled = YES;
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[UIApplication sharedApplication].idleTimerDisabled = self.applicationIdleTimerDisabled;
[super viewWillDisappear:animated];
}
- (BOOL)prefersStatusBarHidden {
return NO;
}
- (void)playVideoWithStreamURL:(NSURL*)streamURL {
[self.player loadVideoWithTrack:[[VKVideoPlayerTrack alloc] initWithStreamURL:streamURL]];
}
- (void)setSubtitle:(VKVideoPlayerCaption*)subtitle {
[self.player setCaptionToBottom:subtitle];
}
#pragma mark - App States
- (void)applicationWillResignActive {
self.player.view.controlHideCountdown = -1;
if (self.player.state == VKVideoPlayerStateContentPlaying) [self.player pauseContent:NO completionHandler:nil];
}
- (void)applicationDidBecomeActive {
self.player.view.controlHideCountdown = kPlayerControlsDisableAutoHide;
}
#pragma mark - VKVideoPlayerControllerDelegate
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didControlByEvent:(VKVideoPlayerControlEvent)event {
if (event == VKVideoPlayerControlEventTapDone) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - Orientation
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (self.player.isFullScreen) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
} else {
return NO;
}
}
@end