Commit d95682d0 authored by Felix Paul Kühne's avatar Felix Paul Kühne

add a setting to control the audio playback when the app is in background

additionally, add a header to collect the string constants used to provide the settings within the app
parent 5ce352a1
......@@ -16,6 +16,8 @@
#import <MobileVLCKit/MobileVLCKit.h>
#import <MediaLibraryKit/MediaLibraryKit.h>
#import "VLCConstants.h"
#ifndef NDEBUG
#define APLog(format, ...) NSLog(format, ## __VA_ARGS__)
#else
......
......@@ -18,7 +18,7 @@
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = @{@"Passcode" : @"", @"PasscodeProtection" : @0};
NSDictionary *appDefaults = @{kVLCSettingPasscodeKey : @"", kVLCSettingPasscodeOnKey : @0, kVLCSettingContinueAudioInBackgroundKey : @1};
[defaults registerDefaults:appDefaults];
}
......
//
// VLCConstants.h
// VLC for iOS
//
// Created by Felix Paul Kühne on 20.05.13.
// Copyright (c) 2013 VideoLAN. All rights reserved.
//
#define kVLCSettingPasscodeKey @"Passcode"
#define kVLCSettingPasscodeOnKey @"PasscodeProtection"
#define kVLCSettingContinueAudioInBackgroundKey @"BackgroundAudioPlayback"
\ No newline at end of file
......@@ -13,6 +13,10 @@
#define INPUT_RATE_DEFAULT 1000.
@interface VLCMovieViewController () <UIGestureRecognizerDelegate>
{
BOOL _shouldResumePlaying;
}
@property (nonatomic, strong) UIPopoverController *masterPopoverController;
@property (nonatomic, strong) UIWindow *externalWindow;
@end
......@@ -60,7 +64,12 @@
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleExternalScreenDidDisconnect:)
name:UIScreenDidDisconnectNotification object:nil];
[center addObserver:self selector:@selector(appWillResign:) name:UIApplicationWillResignActiveNotification object:nil];
[center addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
[center addObserver:self selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];
[center addObserver:self selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
_playingExternallyTitle.text = NSLocalizedString(@"PLAYING_EXTERNALLY_TITLE", @"");
_playingExternallyDescription.text = NSLocalizedString(@"PLAYING_EXTERNALLY_DESC", @"");
......@@ -535,11 +544,33 @@
}
}
#pragma mark -
#pragma mark - background interaction
- (void)appWillResign:(NSNotification *)aNotification
- (void)applicationWillResignActive:(NSNotification *)aNotification
{
NSLog(@"applicationWillResignActive");
self.mediaItem.lastPosition = @([_mediaPlayer position]);
if (![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioInBackgroundKey] intValue]) {
NSLog(@"pausing playback");
[_mediaPlayer pause];
_shouldResumePlaying = YES;
} else
NSLog(@"continuing playback");
}
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
_shouldResumePlaying = NO;
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
NSLog(@"applicationDidBecomeActive");
if (_shouldResumePlaying) {
_shouldResumePlaying = NO;
[_mediaPlayer play];
}
}
#pragma mark - autorotation
......
......@@ -14,7 +14,12 @@
@property (nonatomic, strong) IBOutlet UISwitch *passcodeLockSwitch;
@property (nonatomic, strong) IBOutlet UILabel *passcodeLockLabel;
@property (nonatomic, strong) IBOutlet UISwitch *audioPlaybackInBackgroundSwitch;
@property (nonatomic, strong) IBOutlet UILabel *audioPlaybackInBackgroundLabel;
- (IBAction)togglePasscodeLockSetting:(id)sender;
- (IBAction)toggleAudioInBackGroundSetting:(id)sender;
- (IBAction)dismiss:(id)sender;
@end
......
......@@ -25,12 +25,14 @@
self.dismissButton.title = NSLocalizedString(@"BUTTON_DONE", @"");
self.passcodeLockLabel.text = NSLocalizedString(@"PREF_PASSCODE", @"");
self.audioPlaybackInBackgroundLabel.text = NSLocalizedString(@"PREF_AUDIOBACKGROUND", @"");
}
- (void)viewWillAppear:(BOOL)animated
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.passcodeLockSwitch.on = [[defaults objectForKey:@"PasscodeProtection"] intValue];
self.passcodeLockSwitch.on = [[defaults objectForKey:kVLCSettingPasscodeOnKey] intValue];
self.audioPlaybackInBackgroundSwitch.on = [[defaults objectForKey:kVLCSettingContinueAudioInBackgroundKey] intValue];
[super viewWillAppear:animated];
}
......@@ -48,11 +50,18 @@
[appDelegate.playlistViewController.passcodeLockViewController resetPasscode];
} else {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@0 forKey:@"PasscodeProtection"];
[defaults setObject:@0 forKey:kVLCSettingPasscodeOnKey];
[defaults synchronize];
}
}
- (IBAction)toggleAudioInBackGroundSetting:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@(self.audioPlaybackInBackgroundSwitch.on) forKey:kVLCSettingContinueAudioInBackgroundKey];
[defaults synchronize];
}
- (IBAction)dismiss:(id)sender
{
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
......
......@@ -174,7 +174,7 @@ IEvDvGhuZSBhbmQgR2xlYiBQaW5pZ2luA</string>
</object>
<object class="IBUIImageView" id="589611976">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">289</int>
<int key="NSvFlags">293</int>
<string key="NSFrame">{{105, 64}, {160, 160}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
......@@ -193,7 +193,6 @@ IEvDvGhuZSBhbmQgR2xlYiBQaW5pZ2luA</string>
<string key="NSFrame">{{84, 257}, {600, 747}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor" id="115530952">
<int key="NSColorSpace">3</int>
......
......@@ -143,7 +143,6 @@
<string key="NSFrame">{{0, 233}, {320, 315}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
......
......@@ -71,7 +71,7 @@
<object class="IBUILabel" id="890162779">
<reference key="NSNextResponder" ref="1058981638"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 75}, {259, 21}}</string>
<string key="NSFrame">{{20, 75}, {415, 21}}</string>
<reference key="NSSuperview" ref="1058981638"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="268284080"/>
......@@ -82,17 +82,17 @@
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Passcode Lock</string>
<object class="NSColor" key="IBUITextColor">
<object class="NSColor" key="IBUITextColor" id="33374124">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
</object>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<object class="IBUIFontDescription" key="IBUIFontDescription" id="210361183">
<int key="type">1</int>
<double key="pointSize">17</double>
</object>
<object class="NSFont" key="IBUIFont">
<object class="NSFont" key="IBUIFont" id="965406955">
<string key="NSName">Helvetica</string>
<double key="NSSize">17</double>
<int key="NSfFlags">16</int>
......@@ -105,6 +105,43 @@
<string key="NSFrame">{{428, 72}, {94, 27}}</string>
<reference key="NSSuperview" ref="1058981638"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="76469752"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
</object>
<object class="IBUILabel" id="76469752">
<reference key="NSNextResponder" ref="1058981638"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{20, 116}, {415, 42}}</string>
<reference key="NSSuperview" ref="1058981638"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="115965713"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Continue audio playback in background</string>
<reference key="IBUITextColor" ref="33374124"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<int key="IBUINumberOfLines">2</int>
<int key="IBUILineBreakMode">0</int>
<reference key="IBUIFontDescription" ref="210361183"/>
<reference key="IBUIFont" ref="965406955"/>
<bool key="IBUIAdjustsFontSizeToFit">NO</bool>
<double key="preferredMaxLayoutWidth">415</double>
</object>
<object class="IBUISwitch" id="115965713">
<reference key="NSNextResponder" ref="1058981638"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{428, 123}, {94, 27}}</string>
<reference key="NSSuperview" ref="1058981638"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
......@@ -163,6 +200,22 @@
</object>
<int key="connectionID">38</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">audioPlaybackInBackgroundLabel</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="76469752"/>
</object>
<int key="connectionID">42</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">audioPlaybackInBackgroundSwitch</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="115965713"/>
</object>
<int key="connectionID">43</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">dismiss:</string>
......@@ -180,6 +233,15 @@
</object>
<int key="connectionID">36</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">toggleAudioInBackGroundSetting:</string>
<reference key="source" ref="115965713"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">13</int>
</object>
<int key="connectionID">44</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
......@@ -207,6 +269,8 @@
<reference ref="222768752"/>
<reference ref="890162779"/>
<reference ref="268284080"/>
<reference ref="76469752"/>
<reference ref="115965713"/>
</array>
<reference key="parent" ref="0"/>
</object>
......@@ -241,6 +305,16 @@
<array class="NSMutableArray" key="children"/>
<reference key="parent" ref="1058981638"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">39</int>
<reference key="object" ref="76469752"/>
<reference key="parent" ref="1058981638"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">40</int>
<reference key="object" ref="115965713"/>
<reference key="parent" ref="1058981638"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
......@@ -253,13 +327,15 @@
<string key="19.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="26.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="39.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="40.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">38</int>
<int key="maxID">44</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
......@@ -268,6 +344,7 @@
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="dismiss:">id</string>
<string key="toggleAudioInBackGroundSetting:">id</string>
<string key="togglePasscodeLockSetting:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
......@@ -275,17 +352,31 @@
<string key="name">dismiss:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="toggleAudioInBackGroundSetting:">
<string key="name">toggleAudioInBackGroundSetting:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="togglePasscodeLockSetting:">
<string key="name">togglePasscodeLockSetting:</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="audioPlaybackInBackgroundLabel">UILabel</string>
<string key="audioPlaybackInBackgroundSwitch">UISwitch</string>
<string key="dismissButton">UIBarButtonItem</string>
<string key="passcodeLockLabel">UILabel</string>
<string key="passcodeLockSwitch">UISwitch</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="audioPlaybackInBackgroundLabel">
<string key="name">audioPlaybackInBackgroundLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="audioPlaybackInBackgroundSwitch">
<string key="name">audioPlaybackInBackgroundSwitch</string>
<string key="candidateClassName">UISwitch</string>
</object>
<object class="IBToOneOutletInfo" key="dismissButton">
<string key="name">dismissButton</string>
<string key="candidateClassName">UIBarButtonItem</string>
......
B"CHOOSE_AUDIO_TRACK"="Audiospur wählen";
......
B"CHOOSE_AUDIO_TRACK"="Choose Audio Track";
......
B"CHOOSE_AUDIO_TRACK"="Choisir Piste Audio";
......
B"CHOOSE_AUDIO_TRACK"="Выберите аудио поток";
......
......@@ -267,6 +267,7 @@
7D6B07BB1716C9B8003280C4 /* UIColor+AQGridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIColor+AQGridView.m"; path = "ImportedSources/AQGridView/Classes/UIColor+AQGridView.m"; sourceTree = SOURCE_ROOT; };
7D6B07F51716D45B003280C4 /* VLCPlaylistGridView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCPlaylistGridView.h; sourceTree = "<group>"; };
7D6B07F61716D45B003280C4 /* VLCPlaylistGridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistGridView.m; sourceTree = "<group>"; };
7D6B08BB174A72A900A05173 /* VLCConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCConstants.h; sourceTree = "<group>"; };
7D6BA10B1747F26300C0E203 /* VLCPasscodeLockViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCPasscodeLockViewController.h; sourceTree = "<group>"; };
7D6BA10C1747F26300C0E203 /* VLCPasscodeLockViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCPasscodeLockViewController.m; sourceTree = "<group>"; };
7D6BA10D1747F26300C0E203 /* VLCPasscodeLockViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCPasscodeLockViewController.xib; path = ../Resources/VLCPasscodeLockViewController.xib; sourceTree = "<group>"; };
......@@ -667,6 +668,7 @@
7D94FCE416DE7D1000F2623B /* AspenProject */ = {
isa = PBXGroup;
children = (
7D6B08BB174A72A900A05173 /* VLCConstants.h */,
7D94FCED16DE7D1000F2623B /* VLCAppDelegate.h */,
7D94FCEE16DE7D1000F2623B /* VLCAppDelegate.m */,
7D94FCF616DE7D1100F2623B /* VLCPlaylistViewController.h */,
......
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