浏览代码

playback: split any non-UI logic from the view controller to a designated global instance

Felix Paul Kühne 10 年之前
父节点
当前提交
ffc3b9ab44

+ 35 - 16
Sources/VLCAppDelegate.m

@@ -31,6 +31,7 @@
 #import "VLCAlertView.h"
 #import <BoxSDK/BoxSDK.h>
 #import "VLCNotificationRelay.h"
+#import "VLCPlaybackController.h"
 
 #define HAVE_FABRIC 0
 
@@ -541,20 +542,23 @@
 {
     if (!_movieViewController)
         _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
-    else
-        [_movieViewController unanimatedPlaybackStop];
+
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
 
     if ([mediaObject isKindOfClass:[MLFile class]])
-        _movieViewController.fileFromMediaLibrary = (MLFile *)mediaObject;
+        vpc.fileFromMediaLibrary = (MLFile *)mediaObject;
     else if ([mediaObject isKindOfClass:[MLAlbumTrack class]])
-        _movieViewController.fileFromMediaLibrary = [(MLAlbumTrack*)mediaObject files].anyObject;
+        vpc.fileFromMediaLibrary = [(MLAlbumTrack*)mediaObject files].anyObject;
     else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
-        _movieViewController.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject;
-    [(MLFile *)_movieViewController.fileFromMediaLibrary setUnread:@(NO)];
+        vpc.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject;
+    [(MLFile *)vpc.fileFromMediaLibrary setUnread:@(NO)];
+    vpc.delegate = _movieViewController;
 
     UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
     navCon.modalPresentationStyle = UIModalPresentationFullScreen;
     [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+
+    [vpc startPlayback];
 }
 
 - (void)openMovieFromURL:(NSURL *)url
@@ -564,13 +568,18 @@
     if (!_movieViewController)
         _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
 
-    _movieViewController.url = url;
-    _movieViewController.successCallback = successCallback;
-    _movieViewController.errorCallback = errorCallback;
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+
+    vpc.url = url;
+    vpc.successCallback = successCallback;
+    vpc.errorCallback = errorCallback;
+    vpc.delegate = _movieViewController;
 
     UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
     navCon.modalPresentationStyle = UIModalPresentationFullScreen;
     [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+
+    [vpc startPlayback];
 }
 
 - (void)openMovieFromURL:(NSURL *)url
@@ -583,13 +592,18 @@
     if (!_movieViewController)
         _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
 
-    _movieViewController.mediaList = list;
-    _movieViewController.itemInMediaListToBePlayedFirst = index;
-    _movieViewController.pathToExternalSubtitlesFile = nil;
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+
+    vpc.mediaList = list;
+    vpc.itemInMediaListToBePlayedFirst = index;
+    vpc.pathToExternalSubtitlesFile = nil;
+    vpc.delegate = _movieViewController;
 
     UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
     navCon.modalPresentationStyle = UIModalPresentationFullScreen;
     [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+
+    [vpc startPlayback];
 }
 
 - (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath
@@ -597,12 +611,17 @@
     if (!_movieViewController)
         _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
 
-    _movieViewController.url = url;
-    _movieViewController.pathToExternalSubtitlesFile = SubtitlePath;
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+
+    vpc.url = url;
+    vpc.pathToExternalSubtitlesFile = SubtitlePath;
+    vpc.delegate = _movieViewController;
 
     UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
     navCon.modalPresentationStyle = UIModalPresentationFullScreen;
     [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+
+    [vpc startPlayback];
 }
 
 #pragma mark - watch struff
@@ -658,14 +677,14 @@
 - (NSDictionary *)nowPlayingResponseDict {
     NSMutableDictionary *response = [NSMutableDictionary new];
     NSMutableDictionary *nowPlayingInfo = [[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo mutableCopy];
-    NSNumber *playbackTime = [_movieViewController mediaPlayer].time.numberValue;
+    NSNumber *playbackTime = [VLCPlaybackController sharedInstance].mediaPlayer.time.numberValue;
     if (playbackTime) {
         nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(playbackTime.floatValue/1000);
     }
     if (nowPlayingInfo) {
         response[@"nowPlayingInfo"] = nowPlayingInfo;
     }
-    MLFile *currentFile = _movieViewController.currentlyPlayingMediaFile;
+    MLFile *currentFile = [VLCPlaybackController sharedInstance].currentlyPlayingMediaFile;
     NSString *URIString = currentFile.objectID.URIRepresentation.absoluteString;
     if (URIString) {
         response[@"URIRepresentation"] = URIString;

+ 8 - 0
Sources/VLCEqualizerView.h

@@ -25,10 +25,18 @@
 
 @end
 
+@protocol VLCEqualizerViewUIDelegate <NSObject>
+
+@optional
+- (void)equalizerViewReceivedUserInput;
+
+@end
+
 @interface VLCEqualizerView : VLCFrostedGlasView <UITableViewDataSource,UITableViewDelegate>
 
 @property (nonatomic, strong) UITableView *tableView;
 @property (weak) id <VLCEqualizerViewDelegate>delegate;
+@property (weak) id <VLCEqualizerViewUIDelegate>UIdelegate;
 
 - (void)reloadData;
 

+ 4 - 0
Sources/VLCEqualizerView.m

@@ -268,12 +268,16 @@
 {
     if (self.delegate)
         [self.delegate setAmplification:[sender value] forBand:(unsigned)[sender tag]];
+    if ([self.UIdelegate respondsToSelector:@selector(equalizerViewReceivedUserInput)])
+        [self.UIdelegate equalizerViewReceivedUserInput];
 }
 
 - (IBAction)preampSliderChangedValue:(VLCSlider *)sender
 {
     if (self.delegate)
         [self.delegate setPreAmplification:sender.value];
+    if ([self.UIdelegate respondsToSelector:@selector(equalizerViewReceivedUserInput)])
+        [self.UIdelegate equalizerViewReceivedUserInput];
 }
 
 - (void)reloadData

+ 2 - 14
Sources/VLCMovieViewController.h

@@ -13,13 +13,14 @@
 
 #import <MediaPlayer/MediaPlayer.h>
 #import "VLCFrostedGlasView.h"
+#import "VLCPlaybackController.h"
 
 @class OBSlider;
 @class VLCStatusLabel;
 @class VLCHorizontalSwipeGestureRecognizer;
 @class VLCVerticalSwipeGestureRecognizer;
 
-@interface VLCMovieViewController : UIViewController <VLCMediaPlayerDelegate, UIActionSheetDelegate>
+@interface VLCMovieViewController : UIViewController <UIActionSheetDelegate, VLCPlaybackControllerDelegate>
 
 @property (nonatomic, strong) IBOutlet UIView *movieView;
 @property (nonatomic, strong) IBOutlet UIBarButtonItem *backButton;
@@ -84,20 +85,7 @@
 @property (nonatomic, strong) IBOutlet UILabel *trackNameLabel;
 @property (nonatomic, strong) IBOutlet UIImageView *artworkImageView;
 
-@property (nonatomic, strong) MLFile *fileFromMediaLibrary;
-@property (nonatomic, strong) NSURL *url;
-@property (nonatomic, strong) NSURL *successCallback;
-@property (nonatomic, strong) NSURL *errorCallback;
-@property (nonatomic, strong) NSString *pathToExternalSubtitlesFile;
-@property (nonatomic, retain) VLCMediaList *mediaList;
-@property (nonatomic, strong) VLCMediaPlayer *mediaPlayer;
-@property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;
-
-/* returns nil if currenlty plaing item is not a MLFile, e.g. a url */
-@property (nonatomic, strong, readonly) MLFile *currentlyPlayingMediaFile;
-
 - (IBAction)closePlayback:(id)sender;
-- (void)unanimatedPlaybackStop;
 
 - (IBAction)positionSliderAction:(id)sender;
 - (IBAction)positionSliderTouchDown:(id)sender;

文件差异内容过多而无法显示
+ 213 - 1063
Sources/VLCMovieViewController.m


+ 82 - 0
Sources/VLCPlaybackController.h

@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * VLCPlaybackController.h
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan.org>
+ *          Tobias Conradi <videolan # tobias-conradi.de>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import "VLCEqualizerView.h"
+
+@class VLCPlaybackController;
+
+@protocol VLCPlaybackControllerDelegate <NSObject>
+
+- (void)playbackPositionUpdated:(VLCPlaybackController *)controller;
+- (void)playbackRateUpdated:(float)rate forPlaybackController:(VLCPlaybackController *)controller;
+- (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState
+                      isPlaying:(BOOL)isPlaying
+currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
+        currentMediaHasChapters:(BOOL)currentMediaHasChapters
+          forPlaybackController:(VLCPlaybackController *)controller;
+- (void)prepareForMediaPlayback:(VLCPlaybackController *)controller;
+- (void)presentingViewControllerShouldBeClosed:(VLCPlaybackController *)controller;
+- (void)presentingViewControllerShouldBeClosedAfterADelay:(VLCPlaybackController *)controller;
+- (void)showStatusMessage:(NSString *)statusMessage forPlaybackController:(VLCPlaybackController *)controller;
+- (void)audioOnlyPlaybackWasDetected:(BOOL)audioOnly forPlaybackController:(VLCPlaybackController *)controller;
+- (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller
+                                       title:(NSString *)title
+                                     artwork:(UIImage *)artwork
+                                      artist:(NSString *)artist
+                                       album:(NSString *)album
+                                   audioOnly:(BOOL)audioOnly;
+
+@end
+
+@interface VLCPlaybackController : NSObject <VLCEqualizerViewDelegate>
+
+@property (nonatomic, readonly) VLCMediaListPlayer *listPlayer;
+@property (nonatomic, readonly) VLCMediaPlayer *mediaPlayer;
+
+@property (nonatomic, strong) UIView *videoOutputView;
+
+@property (nonatomic, strong) MLFile *fileFromMediaLibrary;
+@property (nonatomic, strong) NSURL *url;
+@property (nonatomic, strong) NSURL *successCallback;
+@property (nonatomic, strong) NSURL *errorCallback;
+
+@property (nonatomic, strong) NSString *pathToExternalSubtitlesFile;
+@property (nonatomic, retain) VLCMediaList *mediaList;
+@property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;
+
+/* returns nil if currenlty plaing item is not a MLFile, e.g. a url */
+@property (nonatomic, strong, readonly) MLFile *currentlyPlayingMediaFile;
+
+@property (nonatomic, weak) id<VLCPlaybackControllerDelegate> delegate;
+
+@property (nonatomic, readonly) VLCMediaPlayerState mediaPlayerState;
+@property (nonatomic, readonly) NSInteger mediaDuration;
+@property (nonatomic, readonly) BOOL isPlaying;
+@property (nonatomic, readwrite) VLCRepeatMode repeatMode;
+@property (nonatomic, readwrite) float playbackRate;
+@property (nonatomic, readonly) BOOL currentMediaHasChapters;
+@property (nonatomic, readonly) BOOL currentMediaHasTrackToChooseFrom;
+
++ (VLCPlaybackController *)sharedInstance;
+
+- (void)startPlayback;
+- (void)stopPlayback;
+
+- (void)playPause;
+- (void)forward;
+- (void)backward;
+- (void)switchAspectRatio;
+
+- (void)recoverDisplayedMetadata;
+
+@end

文件差异内容过多而无法显示
+ 1076 - 0
Sources/VLCPlaybackController.m


+ 6 - 0
VLC for iOS.xcodeproj/project.pbxproj

@@ -430,6 +430,7 @@
 		7DE1862C175BA9A9006C0173 /* badgeUnread@2x~iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DE1862E175BA9A9006C0173 /* badgeUnread@2x~iphone.png */; };
 		7DE1862F175BA9AC006C0173 /* badgeUnread~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DE18631175BA9AC006C0173 /* badgeUnread~ipad.png */; };
 		7DE18632175BA9AF006C0173 /* badgeUnread~iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DE18634175BA9AF006C0173 /* badgeUnread~iphone.png */; };
+		7DE56C1A1AD93F9100E8CA00 /* VLCPlaybackController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DE56C191AD93F9100E8CA00 /* VLCPlaybackController.m */; };
 		7DE715ED1AD2DAE50075E716 /* VLCThumbnailsCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D37849D183A98DD009EE944 /* VLCThumbnailsCache.m */; };
 		7DEB3B5D17647B240038FC70 /* bottomBlackBar@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DEB3B5B17647B240038FC70 /* bottomBlackBar@2x.png */; };
 		7DEB3B5E17647B240038FC70 /* bottomBlackBar.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DEB3B5C17647B240038FC70 /* bottomBlackBar.png */; };
@@ -1388,6 +1389,8 @@
 		7DE18646175BAEC0006C0173 /* fr */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = fr; path = "fr.lproj/badgeUnread~ipad.png"; sourceTree = "<group>"; };
 		7DE18647175BAEC1006C0173 /* it */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = it; path = "it.lproj/badgeUnread~ipad.png"; sourceTree = "<group>"; };
 		7DE18648175BAEC2006C0173 /* ja */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ja; path = "ja.lproj/badgeUnread~ipad.png"; sourceTree = "<group>"; };
+		7DE56C181AD93F9100E8CA00 /* VLCPlaybackController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCPlaybackController.h; path = Sources/VLCPlaybackController.h; sourceTree = SOURCE_ROOT; };
+		7DE56C191AD93F9100E8CA00 /* VLCPlaybackController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCPlaybackController.m; path = Sources/VLCPlaybackController.m; sourceTree = SOURCE_ROOT; };
 		7DEB3B5B17647B240038FC70 /* bottomBlackBar@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bottomBlackBar@2x.png"; sourceTree = "<group>"; };
 		7DEB3B5C17647B240038FC70 /* bottomBlackBar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bottomBlackBar.png; sourceTree = "<group>"; };
 		7DEB3B5F17647DE30038FC70 /* iTunesArtwork@2x */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTunesArtwork@2x"; sourceTree = "<group>"; };
@@ -2270,6 +2273,8 @@
 		7D5F7AB9175265B2006CCCFA /* Playback */ = {
 			isa = PBXGroup;
 			children = (
+				7DE56C181AD93F9100E8CA00 /* VLCPlaybackController.h */,
+				7DE56C191AD93F9100E8CA00 /* VLCPlaybackController.m */,
 				7D37848D183A98B6009EE944 /* VLCMovieViewController.h */,
 				7D37848E183A98B6009EE944 /* VLCMovieViewController.m */,
 				7D378490183A98BF009EE944 /* VLCExternalDisplayController.h */,
@@ -3676,6 +3681,7 @@
 				7D168F7418D4A33F003FAF59 /* UIImage+Blur.m in Sources */,
 				9B5BEF2917FBAEA50016F9CB /* GTLDrive_Sources.m in Sources */,
 				7DC19ADF1868C7BB00810BF7 /* VLCFirstStepsViewController.m in Sources */,
+				7DE56C1A1AD93F9100E8CA00 /* VLCPlaybackController.m in Sources */,
 				7DC72D6317B7ED24008A26D0 /* WhiteRaccoon.m in Sources */,
 				7D5CAA891A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m in Sources */,
 				7D63C19018774B1700BD5256 /* VLCFirstStepsSecondPageViewController.m in Sources */,