Преглед на файлове

add volume slider to Now Playing Interface

Tobias Conradi преди 10 години
родител
ревизия
219932afa6

+ 17 - 0
Sources/VLCAppDelegate.m

@@ -674,6 +674,8 @@
         [[VLCPlaybackController sharedInstance] backward];
     } else if ([userInfo[@"name"] isEqualToString:@"playFile"]) {
         [self playFileFromWatch:userInfo[@"userInfo"]];
+    } else if ([userInfo[@"name"] isEqualToString:@"setVolume"]) {
+        [self setVolumeFromWatch:userInfo[@"userInfo"]];
     } else {
         NSLog(@"Did not handle request from WatchKit Extension: %@",userInfo);
     }
@@ -696,6 +698,18 @@
     [self openMediaFromManagedObject:managedObject];
 }
 
+- (void)setVolumeFromWatch:(NSDictionary *)userInfo
+{
+    NSNumber *volume = userInfo[@"volume"];
+    if ([volume isKindOfClass:[NSNumber class]]) {
+        /*
+         * Since WatchKit doen't provide something like MPVolumeView we use deprecated API.
+         * rdar://20783803 Feature Request: WatchKit equivalent for MPVolumeView
+         */
+        [MPMusicPlayerController applicationMusicPlayer].volume = volume.floatValue;
+    }
+}
+
 - (NSDictionary *)nowPlayingResponseDict {
     NSMutableDictionary *response = [NSMutableDictionary new];
     NSMutableDictionary *nowPlayingInfo = [[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo mutableCopy];
@@ -711,6 +725,9 @@
     if (URIString) {
         response[@"URIRepresentation"] = URIString;
     }
+
+    response[@"volume"] = @([MPMusicPlayerController applicationMusicPlayer].volume);
+
     return response;
 }
 

+ 11 - 3
VLC for iOS WatchKit App/Base.lproj/Interface.storyboard

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="AgC-eL-Hgc">
+<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="AgC-eL-Hgc">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="3737"/>
     </dependencies>
     <scenes>
@@ -122,7 +122,7 @@
                     <items>
                         <group width="1" height="1" heightAdjustment="-2" alignment="left" verticalAlignment="center" contentMode="scaleAspectFit" layout="vertical" id="uwS-0S-Ag2">
                             <items>
-                                <group width="1" height="1" heightAdjustment="-30" alignment="left" contentMode="scaleAspectFit" id="iCs-yD-jsj">
+                                <group width="1" height="1" heightAdjustment="-55" alignment="left" contentMode="scaleAspectFit" layout="vertical" id="iCs-yD-jsj">
                                     <items>
                                         <group alignment="center" verticalAlignment="center" spacing="25" id="egl-IT-539">
                                             <items>
@@ -147,7 +147,14 @@
                                             </items>
                                         </group>
                                     </items>
+                                    <variation key="device=watch42mm" heightAdjustment="-60"/>
                                 </group>
+                                <slider width="1" alignment="left" verticalAlignment="bottom" continuous="YES" value="0.5" steps="16" id="WNd-eJ-DzK">
+                                    <color key="color" red="1" green="0.50196081400000003" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
+                                    <connections>
+                                        <action selector="volumeSliderChanged:" destination="Mzo-Y8-gdK" id="8uu-ZX-J9P"/>
+                                    </connections>
+                                </slider>
                                 <group width="1" alignment="left" verticalAlignment="bottom" id="d9m-EJ-n3r">
                                     <items>
                                         <label width="100" alignment="left" verticalAlignment="bottom" accessibilityLabel="title" text="title" id="H58-Y8-Tbc">
@@ -173,6 +180,7 @@
                         <outlet property="playPauseButton" destination="BAZ-aC-ETt" id="X17-bz-cFy"/>
                         <outlet property="progressObject" destination="9DQ-Bn-k5Y" id="LK1-eS-RGv"/>
                         <outlet property="titleLabel" destination="H58-Y8-Tbc" id="xZs-ZW-Shj"/>
+                        <outlet property="volumeSlider" destination="WNd-eJ-DzK" id="IyP-bA-Qmf"/>
                     </connections>
                 </controller>
             </objects>

+ 2 - 0
VLC for iOS WatchKit Extension/VLCNowPlayingInterfaceController.h

@@ -19,10 +19,12 @@
 @property (weak, nonatomic) IBOutlet WKInterfaceLabel *durationLabel;
 @property (weak, nonatomic) IBOutlet WKInterfaceButton *playPauseButton;
 @property (weak, nonatomic) IBOutlet WKInterfaceObject *progressObject;
+@property (weak, nonatomic) IBOutlet WKInterfaceSlider *volumeSlider;
 
 - (IBAction)playPausePressed;
 - (IBAction)skipForward;
 - (IBAction)skipBackward;
+- (IBAction)volumeSliderChanged:(float)value;
 
 
 @end

+ 26 - 0
VLC for iOS WatchKit Extension/VLCNowPlayingInterfaceController.m

@@ -28,6 +28,7 @@
 @property (nonatomic, getter=isPlaying) BOOL playing;
 @property (nonatomic) NSTimer *updateTimer;
 @property (nonatomic, weak) MLFile *currentFile;
+@property (nonatomic) float volume;
 @end
 
 @implementation VLCNowPlayingInterfaceController
@@ -78,6 +79,10 @@
             file = [MLFile fileForURIRepresentation:uriRepresentation];
         }
         [self updateWithNowPlayingInfo:replyInfo[@"nowPlayingInfo"] andFile:file];
+        NSNumber *currentVolume = replyInfo[@"volume"];
+        if (currentVolume) {
+            self.volume = currentVolume.floatValue;
+        }
     }];
 }
 
@@ -144,6 +149,27 @@
     }];
 }
 
+- (IBAction)volumeSliderChanged:(float)value {
+    _volume = value;
+    NSDictionary *dict = @{@"name" : @"setVolume",
+                           @"userInfo" : @{
+                                   @"volume" : @(value)
+                                   },
+                           };
+    [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
+        if (error)
+            NSLog(@"setVolume failed with reply %@ error: %@",replyInfo,error);
+    }];
+}
+
+
+- (void)setVolume:(float)volume
+{
+    if (_volume != volume) {
+        _volume = volume;
+        self.volumeSlider.value = volume;
+    }
+}
 
 - (void)setPlaying:(BOOL)playing {
     if (_playing != playing) {