Browse Source

VLCNetworkServerBrowserUPnP: Add multi-protocol handling (closes #55)

If a media have multiple URI with an image, the image was choosed as the
default URI. Hence, this blocked the streaming of some media and could
even lead to a crash with a big media folders.
This patch fixes temporarily this issue waiting for the integration of the
libvlc's services discovery and the de-integration of upnpx.
Additionally, adds constants of protocols.

(cherry picked from commit 221e2d9a0c38d29c66f7e160fab3b8d0b67f5d73)
Soomin Lee 8 years ago
parent
commit
7777fcf268

+ 4 - 1
SharedSources/ServerBrowsing/UPnP/VLCNetworkServerBrowserUPnP.h

@@ -12,6 +12,9 @@
 
 #import "VLCNetworkServerBrowser-Protocol.h"
 
+#define kVLCUPnPVideoProtocolKey @"http-get:*:video/"
+#define kVLCUPnPAudioProtocolKey @"http-get:*:audio/"
+
 NS_ASSUME_NONNULL_BEGIN
 @class MediaServer1Device;
 @interface VLCNetworkServerBrowserUPnP : NSObject <VLCNetworkServerBrowser>
@@ -45,4 +48,4 @@ NS_ASSUME_NONNULL_BEGIN
 @end
 
 
-NS_ASSUME_NONNULL_END
+NS_ASSUME_NONNULL_END

+ 13 - 7
SharedSources/ServerBrowsing/UPnP/VLCNetworkServerBrowserUPnP.m

@@ -113,7 +113,7 @@
 
     // Provide users with a descriptive action sheet for them to choose based on the multiple resources advertised by DLNA devices (HDHomeRun for example)
 
-    NSRange position = [key rangeOfString:@"http-get:*:video/"];
+    NSRange position = [key rangeOfString:kVLCUPnPVideoProtocolKey];
 
     if (position.location == NSNotFound)
         return nil;
@@ -245,23 +245,29 @@
                     return NO;
 
                 if ([evaluatedObject respondsToSelector:@selector(containsString:)]) {
-                    if ([evaluatedObject containsString:@"http-get:*:video/"])
+                    if ([evaluatedObject containsString:kVLCUPnPVideoProtocolKey])
                         return YES;
-                    if ([evaluatedObject containsString:@"http-get:*:audio/"])
+                    if ([evaluatedObject containsString:kVLCUPnPAudioProtocolKey])
                         return YES;
                 } else {
-                    NSRange foundRange = [evaluatedObject rangeOfString:@"http-get:*:video/"];
+                    NSRange foundRange = [evaluatedObject rangeOfString:kVLCUPnPVideoProtocolKey];
                     if (foundRange.location != NSNotFound)
                         return YES;
-                    foundRange = [evaluatedObject rangeOfString:@"http-get:*:audio/"];
+                    foundRange = [evaluatedObject rangeOfString:kVLCUPnPAudioProtocolKey];
                     if (foundRange.location != NSNotFound)
                         return YES;
                 }
                 return NO;
             }]];
-            /* FIXME: on some servers, we can have more than 1 protocol string as different transcoding schemes are offered
-             * in previous versions, we offered a selector - maybe re-add? */
 
+            // Check for multiple URIs.
+            if ([mediaItem.uriCollection count] > 1) {
+                for (NSString *key in mediaItem.uriCollection) {
+                    if ([key containsString:kVLCUPnPVideoProtocolKey] || [key containsString:kVLCUPnPAudioProtocolKey]) {
+                        mediaItem.uri = [mediaItem.uriCollection objectForKey:key];
+                    }
+                }
+            }
             _URL = [NSURL URLWithString:[mediaItem uri]];
         }
     }