]> git.sesse.net Git - vlc/commitdiff
macosx/framework: Export -[VLCMediaPlayer remainingTime] and -[VLCTime verboseStringV...
authorPierre d'Herbemont <pdherbemont@free.fr>
Mon, 7 Dec 2009 07:58:21 +0000 (08:58 +0100)
committerPierre d'Herbemont <pdherbemont@free.fr>
Mon, 7 Dec 2009 07:59:38 +0000 (08:59 +0100)
projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
projects/macosx/framework/Headers/Public/VLCTime.h
projects/macosx/framework/Sources/VLCMediaPlayer.m
projects/macosx/framework/Sources/VLCTime.m

index f8347f33c85d0dfad8f9c222a1a9dd1a653d8919..0da9e463d2365f52d243e469c4ce39b85fd62816 100644 (file)
@@ -153,6 +153,8 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
  */
 - (VLCTime *)time;
 
+@property (readonly) VLCTime *remainingTime;
+
 - (void)setChapter:(int)value;
 - (int)chapter;
 - (int)countOfChapters;
index cf1d8c5e10b12b3f48ceb99ce7dae8a8996b69a1..69e885175dab048afa368c3a7be7654a76c7f627 100644 (file)
@@ -44,6 +44,7 @@
 /* Properties */
 @property (readonly) NSNumber * numberValue;
 @property (readonly) NSString * stringValue;
+@property (readonly) NSString * verboseStringValue;
 @property (readonly) int intValue;
 
 /* Comparitors */
index b698267d753e42e9e1dab2808e2adeaef4220e01..4954260400721a8c58c3e4069f80b4e3055e8886 100644 (file)
@@ -384,6 +384,13 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void *
     return cachedTime;
 }
 
+- (VLCTime *)remainingTime
+{
+    double currentTime = [[cachedTime numberValue] doubleValue];
+    double remaining = currentTime / position * (1 - position);
+    return [VLCTime timeWithNumber:[NSNumber numberWithDouble:-remaining]];
+}
+
 - (void)setChapter:(int)value;
 {
     libvlc_media_player_set_chapter( instance, value, NULL );
@@ -726,9 +733,11 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime
 {
     [self willChangeValueForKey:@"time"];
+    [self willChangeValueForKey:@"remainingTime"];
     [cachedTime release];
     cachedTime = [[VLCTime timeWithNumber:newTime] retain];
 
+    [self didChangeValueForKey:@"remainingTime"];
     [self didChangeValueForKey:@"time"];
 }
 
index 76510f000ff20820b18440fee09381fabfe67aca..163d74769ccb1c3709d801e77c9496d23ddfd37e 100644 (file)
     }
 }
 
+- (NSString *)verboseStringValue
+{
+    if (value)
+    {
+        long long duration = [value longLongValue] / 1000000;
+        long long positiveDuration = llabs(duration);
+        long hours = positiveDuration / 3600;
+        long mins = (positiveDuration / 60) % 60;
+        long seconds = positiveDuration % 60;
+        const char * remaining = duration < 0 ? " remaining" : "";
+        if (hours > 0)
+            return [NSString stringWithFormat:@"%d hours %d minutes%s", hours, mins, remaining];
+        else if (mins > 5)
+            return [NSString stringWithFormat:@"%d minutes%s", mins, remaining];
+        else
+            return [NSString stringWithFormat:@"%d seconds%s", seconds, remaining];
+    }
+    else
+    {
+        // Return a string that represents an undefined time.
+        return @"";
+    }
+}
+
 - (int)intValue
 {
     if( value )