[vlc-devel] commit: macosx/framework: Export -[VLCMediaPlayer remainingTime] and -[ VLCTime verboseStringValue]. (Pierre d'Herbemont )
git version control
git at videolan.org
Mon Dec 7 08:59:43 CET 2009
vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Mon Dec 7 08:58:21 2009 +0100| [3e5fe8b624f5edad4a7a7ba58ae72fa1709d767f] | committer: Pierre d'Herbemont
macosx/framework: Export -[VLCMediaPlayer remainingTime] and -[VLCTime verboseStringValue].
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3e5fe8b624f5edad4a7a7ba58ae72fa1709d767f
---
.../framework/Headers/Public/VLCMediaPlayer.h | 2 +
projects/macosx/framework/Headers/Public/VLCTime.h | 1 +
projects/macosx/framework/Sources/VLCMediaPlayer.m | 9 +++++++
projects/macosx/framework/Sources/VLCTime.m | 24 ++++++++++++++++++++
4 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h b/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
index f8347f3..0da9e46 100644
--- a/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
+++ b/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
@@ -153,6 +153,8 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
*/
- (VLCTime *)time;
+ at property (readonly) VLCTime *remainingTime;
+
- (void)setChapter:(int)value;
- (int)chapter;
- (int)countOfChapters;
diff --git a/projects/macosx/framework/Headers/Public/VLCTime.h b/projects/macosx/framework/Headers/Public/VLCTime.h
index cf1d8c5..69e8851 100644
--- a/projects/macosx/framework/Headers/Public/VLCTime.h
+++ b/projects/macosx/framework/Headers/Public/VLCTime.h
@@ -44,6 +44,7 @@
/* Properties */
@property (readonly) NSNumber * numberValue;
@property (readonly) NSString * stringValue;
+ at property (readonly) NSString * verboseStringValue;
@property (readonly) int intValue;
/* Comparitors */
diff --git a/projects/macosx/framework/Sources/VLCMediaPlayer.m b/projects/macosx/framework/Sources/VLCMediaPlayer.m
index b698267..4954260 100644
--- a/projects/macosx/framework/Sources/VLCMediaPlayer.m
+++ b/projects/macosx/framework/Sources/VLCMediaPlayer.m
@@ -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"];
}
diff --git a/projects/macosx/framework/Sources/VLCTime.m b/projects/macosx/framework/Sources/VLCTime.m
index 76510f0..163d747 100644
--- a/projects/macosx/framework/Sources/VLCTime.m
+++ b/projects/macosx/framework/Sources/VLCTime.m
@@ -117,6 +117,30 @@
}
}
+- (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 )
More information about the vlc-devel
mailing list