Explorar o código

ATV: implement visual error handling if playback failed or device is too slow for media

Felix Paul Kühne %!s(int64=9) %!d(string=hai) anos
pai
achega
a2e851abcf

+ 22 - 2
Sources/VLCPlaybackController.m

@@ -21,6 +21,7 @@
 #import "UIDevice+VLC.h"
 #import <AVFoundation/AVFoundation.h>
 #import <MediaPlayer/MediaPlayer.h>
+#import "VLCPlayerDisplayController.h"
 
 #if TARGET_OS_IOS
 #import "VLCKeychainCoordinator.h"
@@ -253,16 +254,35 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
     }
     [_listPlayer setRepeatMode:VLCDoNotRepeat];
 
-#if TARGET_OS_IOS
     if (![self _isMediaSuitableForDevice:media]) {
+#if TARGET_OS_IOS
         VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DEVICE_TOOSLOW_TITLE", nil)
                                                           message:[NSString stringWithFormat:NSLocalizedString(@"DEVICE_TOOSLOW", nil), [[UIDevice currentDevice] model], media.url.lastPathComponent]
                                                          delegate:self
                                                 cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
                                                 otherButtonTitles:NSLocalizedString(@"BUTTON_OPEN", nil), nil];
         [alert show];
-    } else
+#else
+        UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"DEVICE_TOOSLOW_TITLE", nil)
+                                                                       message:[NSString stringWithFormat:NSLocalizedString(@"DEVICE_TOOSLOW", nil), [[UIDevice currentDevice] model], media.url.lastPathComponent]
+                                                                preferredStyle:UIAlertControllerStyleAlert];
+
+        UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OPEN", nil)
+                                                                style:UIAlertActionStyleDefault
+                                                              handler:^(UIAlertAction * action) {
+                                                                      [self _playNewMedia];
+                                                              }];
+
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
+                                                               style:UIAlertActionStyleDestructive
+                                                            handler:^(UIAlertAction * action) {
+                                                                [self stopPlayback];
+                                                            }];
+        [alert addAction:defaultAction];
+        [alert addAction:cancelAction];
+        [[[VLCPlayerDisplayController sharedInstance] childViewController] presentViewController:alert animated:YES completion:nil];
 #endif
+    } else
         [self _playNewMedia];
 }
 

+ 20 - 20
Sources/VLCPlayerDisplayController.m

@@ -47,27 +47,17 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
     [[NSUserDefaults standardUserDefaults] registerDefaults:@{VLCPlayerDisplayControllerDisplayModeKey : @(VLCPlayerDisplayControllerDisplayModeFullscreen)}];
 }
 
-static inline void commonSetup(VLCPlayerDisplayController *self)
+- (instancetype)init
 {
-    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
-    [notificationCenter addObserver:self selector:@selector(playbackDidStart:) name:VLCPlaybackControllerPlaybackDidStart object:nil];
-    [notificationCenter addObserver:self selector:@selector(playbackDidFail:) name:VLCPlaybackControllerPlaybackDidFail object:nil];
-    [notificationCenter addObserver:self selector:@selector(playbackDidStop:) name:VLCPlaybackControllerPlaybackDidStop object:nil];
-}
-
-- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
-{
-    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    self = [super init];
     if (self) {
-        commonSetup(self);
+        NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+        [notificationCenter addObserver:self selector:@selector(playbackDidStart:) name:VLCPlaybackControllerPlaybackDidStart object:nil];
+        [notificationCenter addObserver:self selector:@selector(playbackDidFail:) name:VLCPlaybackControllerPlaybackDidFail object:nil];
+        [notificationCenter addObserver:self selector:@selector(playbackDidStop:) name:VLCPlaybackControllerPlaybackDidStop object:nil];
     }
     return self;
 }
-- (void)awakeFromNib
-{
-    [super awakeFromNib];
-    commonSetup(self);
-}
 
 - (void)dealloc
 {
@@ -221,6 +211,7 @@ static inline void commonSetup(VLCPlayerDisplayController *self)
 - (void)showPlaybackError
 {
     NSString *failedString = NSLocalizedString(@"PLAYBACK_FAILED", nil);
+#if TARGET_OS_IOS
     switch (self.displayMode) {
         case VLCPlayerDisplayControllerDisplayModeFullscreen:
             if ([self.movieViewController respondsToSelector:@selector(showStatusMessage:forPlaybackController:)]) {
@@ -229,17 +220,26 @@ static inline void commonSetup(VLCPlayerDisplayController *self)
             break;
         case VLCPlayerDisplayControllerDisplayModeMiniplayer:
         default:
-#if TARGET_OS_IOS
+
             [[[VLCAlertView alloc] initWithTitle:failedString
                                          message:nil
                                         delegate:nil
                                cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
                                otherButtonTitles:nil] show];
-#else
-            APLog(@"%@", failedString);
-#endif
             break;
     }
+#else
+    UIAlertController *alert = [UIAlertController alertControllerWithTitle:failedString
+                                                                   message:@""
+                                                            preferredStyle:UIAlertControllerStyleAlert];
+
+    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OK", nil)
+                                                            style:UIAlertActionStyleDefault
+                                                          handler:^(UIAlertAction * action) {}];
+
+    [alert addAction:defaultAction];
+    [self presentViewController:alert animated:YES completion:nil];
+#endif
 }
 
 #pragma mark - fullscreen player

+ 1 - 0
VLC for Apple TV/VLCOpenNetworkStreamTVViewController.m

@@ -43,6 +43,7 @@
     _recentURLs = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCRecentURLs]];
     if (_recentURLs.count == 0) {
         [_recentURLs addObject:@"http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4"];
+        [_recentURLs addObject:@"http://streams.videolan.org/streams/mp4/404.mp4"];
     }
     [self.previouslyPlayedStreamsTableView reloadData];
     self.noURLsToShowLabel.hidden = _recentURLs.count != 0;

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

@@ -209,6 +209,7 @@
 		7DEC8BED1BD68D6A006E1093 /* VLCAboutTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DEC8BEB1BD68D6A006E1093 /* VLCAboutTVViewController.m */; };
 		7DEC8C1D1BD6913A006E1093 /* VLCSettingsAboutTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DEC8C1C1BD6913A006E1093 /* VLCSettingsAboutTableViewController.m */; };
 		7DEC8C1E1BD69710006E1093 /* About Contents.html in Resources */ = {isa = PBXBuildFile; fileRef = 7D5DD5C617590ABF001421E3 /* About Contents.html */; };
+		7DEC8C1F1BD6A113006E1093 /* UIDevice+VLC.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784C7183A9972009EE944 /* UIDevice+VLC.m */; };
 		7DF04F4D1961F2B8004A5429 /* web-download-fixed.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DF04F491961F2B8004A5429 /* web-download-fixed.png */; };
 		7DF04F4E1961F2B8004A5429 /* web-download.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DF04F4A1961F2B8004A5429 /* web-download.png */; };
 		7DF04F4F1961F2B8004A5429 /* web-open-fixed.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DF04F4B1961F2B8004A5429 /* web-open-fixed.png */; };
@@ -2273,6 +2274,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				7DEC8C1F1BD6A113006E1093 /* UIDevice+VLC.m in Sources */,
 				7DC71D211BC83058001FACAA /* VLCAppSharesTVViewController.m in Sources */,
 				7DEC8BED1BD68D6A006E1093 /* VLCAboutTVViewController.m in Sources */,
 				7DEC8BD81BD66DA8006E1093 /* VLCMiniPlaybackView.m in Sources */,