[vlc-commits] macosx/player controller: add helpers for media item name, URL and duration
Felix Paul Kühne
git at videolan.org
Wed Mar 27 17:52:54 CET 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Wed Mar 27 16:59:28 2019 +0100| [2f6e22aa4d9d67f778cd737a32ec4e4b1e08d466] | committer: Felix Paul Kühne
macosx/player controller: add helpers for media item name, URL and duration
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2f6e22aa4d9d67f778cd737a32ec4e4b1e08d466
---
.../macosx/coreinteraction/VLCCoreInteraction.m | 59 +-----------------
modules/gui/macosx/playlist/VLCPlayerController.h | 15 +++++
modules/gui/macosx/playlist/VLCPlayerController.m | 70 ++++++++++++++++++++++
3 files changed, 88 insertions(+), 56 deletions(-)
diff --git a/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m b/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
index 0295a83c22..1be0dba2d7 100644
--- a/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
+++ b/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
@@ -197,70 +197,17 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
- (NSInteger)durationOfCurrentPlaylistItem
{
- input_item_t *p_item = _playerController.currentMedia;
-
- if (!p_item) {
- return -1;
- }
-
- vlc_tick_t duration = input_item_GetDuration(p_item);
- input_item_Release(p_item);
-
- return SEC_FROM_VLC_TICK(duration);
+ return SEC_FROM_VLC_TICK(_playerController.durationOfCurrentMediaItem);
}
- (NSURL*)URLOfCurrentPlaylistItem
{
- input_item_t *p_item = _playerController.currentMedia;
- if (!p_item) {
- return nil;
- }
-
- char *psz_url = vlc_uri_decode(input_item_GetURI(p_item));
- if (!psz_url) {
- return nil;
- }
- NSURL *url = [NSURL URLWithString:toNSStr(psz_url)];
- free(psz_url);
- input_item_Release(p_item);
-
- return url;
+ return _playerController.URLOfCurrentMediaItem;
}
- (NSString*)nameOfCurrentPlaylistItem
{
- input_item_t *p_item = _playerController.currentMedia;
- if (!p_item) {
- return nil;
- }
-
- NSString *name;
- static char *tmp_cstr = NULL;
-
- // Get Title
- tmp_cstr = input_item_GetTitleFbName(p_item);
- if (tmp_cstr) {
- name = toNSStr(tmp_cstr);
- FREENULL(tmp_cstr);
- }
-
- if (!name) {
- char *psz_uri = input_item_GetURI(p_item);
- if (!psz_uri) {
- input_item_Release(p_item);
- return nil;
- }
- NSURL *url = [NSURL URLWithString:toNSStr(psz_uri)];
- free(psz_uri);
-
- if ([url isFileURL])
- name = [[NSFileManager defaultManager] displayNameAtPath:[url path]];
- else
- name = [url absoluteString];
- }
-
- input_item_Release(p_item);
- return name;
+ return _playerController.nameOfCurrentMediaItem;
}
- (void)forwardExtraShort
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index dfb977b527..a6d66260d4 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -273,6 +273,21 @@ extern NSString *VLCPlayerMuteChanged;
- (int)setCurrentMedia:(input_item_t *)currentMedia;
/**
+ * returns the duration of the current media in vlc ticks
+ */
+ at property (readonly) vlc_tick_t durationOfCurrentMediaItem;
+
+/**
+ * returns the URL of the current media or NULL if there is none
+ */
+ at property (readonly, copy, nullable) NSURL *URLOfCurrentMediaItem;
+
+/**
+ * returns the name of the current media or NULL if there is none
+ */
+ at property (readonly, copy, nullable) NSString *nameOfCurrentMediaItem;
+
+/**
* the current player state
* @return a value according to the vlc_player_state enum
* @note listen to VLCPlayerStateChanged to be notified about changes to this property
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index be2304bccd..bdbac0fd3e 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -22,6 +22,8 @@
#import "VLCPlayerController.h"
+#import <vlc_url.h>
+
#import "main/VLCMain.h"
#import "os-integration/VLCRemoteControlService.h"
#import "os-integration/iTunes.h"
@@ -652,6 +654,74 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
object:self];
}
+- (vlc_tick_t)durationOfCurrentMediaItem
+{
+ input_item_t *p_item = self.currentMedia;
+
+ if (!p_item) {
+ return -1;
+ }
+
+ vlc_tick_t duration = input_item_GetDuration(p_item);
+ input_item_Release(p_item);
+
+ return duration;
+}
+
+- (NSURL *)URLOfCurrentMediaItem;
+{
+ input_item_t *p_item = self.currentMedia;
+ if (!p_item) {
+ return nil;
+ }
+
+ char *psz_url = vlc_uri_decode(input_item_GetURI(p_item));
+ if (!psz_url) {
+ return nil;
+ }
+ NSURL *url = [NSURL URLWithString:toNSStr(psz_url)];
+ free(psz_url);
+ input_item_Release(p_item);
+
+ return url;
+}
+
+- (NSString*)nameOfCurrentMediaItem;
+{
+ input_item_t *p_item = self.currentMedia;
+ if (!p_item) {
+ return nil;
+ }
+
+ NSString *name;
+ static char *tmp_cstr = NULL;
+
+ // Get Title
+ tmp_cstr = input_item_GetTitleFbName(p_item);
+ if (tmp_cstr) {
+ name = toNSStr(tmp_cstr);
+ FREENULL(tmp_cstr);
+ }
+
+ if (!name) {
+ char *psz_uri = input_item_GetURI(p_item);
+ if (!psz_uri) {
+ input_item_Release(p_item);
+ return nil;
+ }
+ NSURL *url = [NSURL URLWithString:toNSStr(psz_uri)];
+ free(psz_uri);
+
+ if ([url isFileURL])
+ name = [[NSFileManager defaultManager] displayNameAtPath:[url path]];
+ else
+ name = [url absoluteString];
+ }
+
+ input_item_Release(p_item);
+ return name;
+}
+
- (void)stateChanged:(enum vlc_player_state)state
{
/* instead of using vlc_player_GetState, we cache the state and provide it through a synthesized getter
More information about the vlc-commits
mailing list