Commit 8cacd34a authored by Felix Paul Kühne's avatar Felix Paul Kühne

iOS Example - DropIn-Player: add automatic hiding of the UI elements after 5 secs

parent 05d03574
......@@ -42,6 +42,7 @@
- (IBAction)closePlayback:(id)sender;
- (IBAction)positionSliderDrag:(id)sender;
- (IBAction)positionSliderAction:(id)sender;
- (IBAction)toggleTimeDisplay:(id)sender;
......
......@@ -36,6 +36,7 @@
UIActionSheet *_audiotrackActionSheet;
UIActionSheet *_subtitleActionSheet;
NSURL *_url;
NSTimer *_idleTimer;
}
@end
......@@ -62,6 +63,18 @@
self.toolbar.frame = rect;
[self.timeDisplay setTitle:@"" forState:UIControlStateNormal];
/* this looks a bit weird, but let's try to support iOS 5 */
UISlider *volumeSlider = nil;
for (id aView in self.volumeView.subviews){
if ([[[aView class] description] isEqualToString:@"MPVolumeSlider"]){
volumeSlider = (UISlider *)aView;
break;
}
}
[volumeSlider addTarget:self
action:@selector(volumeSliderAction:)
forControlEvents:UIControlEventValueChanged];
/* setup gesture recognizer to toggle controls' visibility */
_movieView.userInteractionEnabled = NO;
UITapGestureRecognizer *tapOnVideoRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleControlsVisible)];
......@@ -106,6 +119,11 @@
_mediaplayer.media = [VLCMedia mediaWithURL:_url];
[_mediaplayer play];
if (self.controllerPanel.hidden)
[self toggleControlsVisible];
[self _resetIdleTimer];
}
......@@ -129,12 +147,25 @@
_mediaplayer = nil;
}
if (_idleTimer) {
[_idleTimer invalidate];
_idleTimer = nil;
}
[self.navigationController setNavigationBarHidden:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}
- (UIResponder *)nextResponder
{
[self _resetIdleTimer];
return [super nextResponder];
}
- (IBAction)positionSliderAction:(UISlider *)sender
{
[self _resetIdleTimer];
/* we need to limit the number of events sent by the slider, since otherwise, the user
* wouldn't see the I-frames when seeking on current mobile devices. This isn't a problem
* within the Simulator, but especially on older ARMv7 devices, it's clearly noticeable. */
......@@ -150,6 +181,16 @@
}
}
- (IBAction)positionSliderDrag:(id)sender
{
[self _resetIdleTimer];
}
- (IBAction)volumeSliderAction:(id)sender
{
[self _resetIdleTimer];
}
- (void)mediaPlayerStateChanged:(NSNotification *)aNotification
{
VLCMediaPlayerState currentState = _mediaplayer.state;
......@@ -177,6 +218,7 @@
- (IBAction)toggleTimeDisplay:(id)sender
{
[self _resetIdleTimer];
_displayRemainingTime = !_displayRemainingTime;
}
......@@ -188,8 +230,32 @@
[[UIApplication sharedApplication] setStatusBarHidden:controlsHidden withAnimation:UIStatusBarAnimationFade];
}
- (void)_resetIdleTimer
{
if (!_idleTimer)
_idleTimer = [NSTimer scheduledTimerWithTimeInterval:5.
target:self
selector:@selector(idleTimerExceeded)
userInfo:nil
repeats:NO];
else {
if (fabs([_idleTimer.fireDate timeIntervalSinceNow]) < 5.)
[_idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:5.]];
}
}
- (void)idleTimerExceeded
{
_idleTimer = nil;
if (!self.controllerPanel.hidden)
[self toggleControlsVisible];
}
- (IBAction)switchVideoDimensions:(id)sender
{
[self _resetIdleTimer];
NSUInteger count = [_aspectRatios count];
if (_currentAspectRatioMask + 1 > count - 1) {
......
......@@ -36,7 +36,7 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="774585933">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIView" id="970364256">
......@@ -44,6 +44,7 @@
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 550}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="254588830"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
......@@ -58,6 +59,7 @@
<array class="NSMutableArray" key="NSSubviews"/>
<string key="NSFrameSize">{320, 44}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="897908297"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
......@@ -79,6 +81,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{139, 13}, {44, 26}}</string>
<reference key="NSSuperview" ref="897908297"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="776049213"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor" id="665591321">
......@@ -117,6 +120,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 13}, {41, 26}}</string>
<reference key="NSSuperview" ref="897908297"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="695335035"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="665591321"/>
......@@ -139,6 +143,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{238, 13}, {62, 26}}</string>
<reference key="NSSuperview" ref="897908297"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="396325696"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="665591321"/>
......@@ -161,12 +166,14 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 47}, {284, 22}}</string>
<reference key="NSSuperview" ref="897908297"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</array>
<string key="NSFrame">{{0, 408}, {320, 82}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="288523396"/>
<string key="NSReuseIdentifierKey">_NS:10</string>
<object class="NSColor" key="IBUIBackgroundColor">
......@@ -177,6 +184,8 @@
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 548}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="970364256"/>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
......@@ -200,7 +209,7 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="646556287">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">290</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUISlider" id="134433983">
......@@ -208,6 +217,7 @@
<int key="NSvFlags">290</int>
<string key="NSFrame">{{5, 10}, {188, 23}}</string>
<reference key="NSSuperview" ref="646556287"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="438248784"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSHuggingPriority">{250, 250}</string>
......@@ -225,6 +235,7 @@
<int key="NSvFlags">289</int>
<string key="NSFrame">{{241, 6}, {59, 29}}</string>
<reference key="NSSuperview" ref="646556287"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
......@@ -240,6 +251,7 @@
<int key="NSvFlags">289</int>
<string key="NSFrame">{{193, 11}, {50, 20}}</string>
<reference key="NSSuperview" ref="646556287"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="637398771"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
......@@ -261,6 +273,8 @@
</object>
</array>
<string key="NSFrameSize">{300, 40}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="134433983"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="665591321"/>
......@@ -381,6 +395,24 @@
</object>
<int key="connectionID">178</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">positionSliderDrag:</string>
<reference key="source" ref="134433983"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">3</int>
</object>
<int key="connectionID">193</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">positionSliderDrag:</string>
<reference key="source" ref="134433983"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">4</int>
</object>
<int key="connectionID">194</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">switchSubtitleTrack:</string>
......@@ -577,9 +609,126 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">192</int>
<int key="maxID">194</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">MPVolumeView</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/MPVolumeView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">VDLPlaybackViewController</string>
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="closePlayback:">id</string>
<string key="playandPause:">id</string>
<string key="positionSliderAction:">UISlider</string>
<string key="positionSliderDrag:">id</string>
<string key="switchAudioTrack:">id</string>
<string key="switchSubtitleTrack:">id</string>
<string key="switchVideoDimensions:">id</string>
<string key="toggleTimeDisplay:">id</string>
<string key="volumeSliderAction:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="closePlayback:">
<string key="name">closePlayback:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="playandPause:">
<string key="name">playandPause:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="positionSliderAction:">
<string key="name">positionSliderAction:</string>
<string key="candidateClassName">UISlider</string>
</object>
<object class="IBActionInfo" key="positionSliderDrag:">
<string key="name">positionSliderDrag:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="switchAudioTrack:">
<string key="name">switchAudioTrack:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="switchSubtitleTrack:">
<string key="name">switchSubtitleTrack:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="switchVideoDimensions:">
<string key="name">switchVideoDimensions:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="toggleTimeDisplay:">
<string key="name">toggleTimeDisplay:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="volumeSliderAction:">
<string key="name">volumeSliderAction:</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="audioSwitcherButton">UIButton</string>
<string key="controllerPanel">UIView</string>
<string key="movieView">UIView</string>
<string key="playPauseButton">UIButton</string>
<string key="positionSlider">UISlider</string>
<string key="subtitleSwitcherButton">UIButton</string>
<string key="timeDisplay">UIButton</string>
<string key="toolbar">UINavigationBar</string>
<string key="volumeView">MPVolumeView</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="audioSwitcherButton">
<string key="name">audioSwitcherButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="controllerPanel">
<string key="name">controllerPanel</string>
<string key="candidateClassName">UIView</string>
</object>
<object class="IBToOneOutletInfo" key="movieView">
<string key="name">movieView</string>
<string key="candidateClassName">UIView</string>
</object>
<object class="IBToOneOutletInfo" key="playPauseButton">
<string key="name">playPauseButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="positionSlider">
<string key="name">positionSlider</string>
<string key="candidateClassName">UISlider</string>
</object>
<object class="IBToOneOutletInfo" key="subtitleSwitcherButton">
<string key="name">subtitleSwitcherButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="timeDisplay">
<string key="name">timeDisplay</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="toolbar">
<string key="name">toolbar</string>
<string key="candidateClassName">UINavigationBar</string>
</object>
<object class="IBToOneOutletInfo" key="volumeView">
<string key="name">volumeView</string>
<string key="candidateClassName">MPVolumeView</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/VDLPlaybackViewController.h</string>
</object>
</object>
</array>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">YES</bool>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment