vlc | branch: master | Felix Paul Kühne <[email protected]> | Sun Apr 7 16:17:12 2019 +0200| [62f810a40a71780f6b37b649fee07d2f61785a39] | committer: Felix Paul Kühne
macosx/player controller: add chapter support > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=62f810a40a71780f6b37b649fee07d2f61785a39 --- modules/gui/macosx/playlist/VLCPlayerController.h | 32 +++++++++++ modules/gui/macosx/playlist/VLCPlayerController.m | 67 ++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h index b50c08f72e..e021779d0c 100644 --- a/modules/gui/macosx/playlist/VLCPlayerController.h +++ b/modules/gui/macosx/playlist/VLCPlayerController.h @@ -92,6 +92,12 @@ extern NSString *VLCPlayerTitleSelectionChanged; extern NSString *VLCPlayerTitleListChanged; /** + * Listen to VLCPlayerChapterSelectionChanged to be notified if the selected chapter of the current title changes + * @note the affected player object will be the object of the notification + */ +extern NSString *VLCPlayerChapterSelectionChanged; + +/** * Listen to VLCPlayerABLoopStateChanged to be notified if the A→B loop state changes * @note the affected player object will be the object of the notification */ @@ -498,6 +504,32 @@ extern NSString *VLCPlayerMuteChanged; - (const struct vlc_player_title *)titleAtIndexForCurrentMedia:(size_t)index; /** + * the index of the currently selected chapter within the current title + * @note listen to VLCPlayerChapterSelectionChanged to be notified about changes to this property + */ +@property (readwrite, nonatomic) size_t selectedChapterIndex; + +/** + * select the next chapter of the current title + */ +- (void)selectNextChapter; + +/** + * select the previous chapter of the current title + */ +- (void)selectPreviousChapter; + +/** + * returns the number of chapters for the current title + */ +@property (readonly) size_t numberOfChaptersForCurrentTitle; + +/** + * returns the chapter for the index within the current title + */ +- (nullable const struct vlc_player_chapter *)chapterAtIndexForCurrentTitle:(size_t)index; + +/** * exposes whether a teletext menu is available or not * @note listen to VLCPlayerTeletextMenuAvailable 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 a4308243a7..e36494217c 100644 --- a/modules/gui/macosx/playlist/VLCPlayerController.m +++ b/modules/gui/macosx/playlist/VLCPlayerController.m @@ -43,6 +43,7 @@ NSString *VLCPlayerTimeAndPositionChanged = @"VLCPlayerTimeAndPositionChanged"; NSString *VLCPlayerLengthChanged = @"VLCPlayerLengthChanged"; NSString *VLCPlayerTitleSelectionChanged = @"VLCPlayerTitleSelectionChanged"; NSString *VLCPlayerTitleListChanged = @"VLCPlayerTitleListChanged"; +NSString *VLCPlayerChapterSelectionChanged = @"VLCPlayerChapterSelectionChanged"; NSString *VLCPlayerABLoopStateChanged = @"VLCPlayerABLoopStateChanged"; NSString *VLCPlayerTeletextMenuAvailable = @"VLCPlayerTeletextMenuAvailable"; NSString *VLCPlayerTeletextEnabled = @"VLCPlayerTeletextEnabled"; @@ -93,6 +94,7 @@ NSString *VLCPlayerMuteChanged = @"VLCPlayerMuteChanged"; - (void)lengthChanged:(vlc_tick_t)length; - (void)titleListChanged:(vlc_player_title_list *)p_titles; - (void)selectedTitleChanged:(size_t)selectedTitle; +- (void)selectedChapterChanged:(size_t)chapterIndex; - (void)teletextAvailibilityChanged:(BOOL)hasTeletextMenu; - (void)teletextEnabledChanged:(BOOL)teletextOn; - (void)teletextPageChanged:(unsigned int)page; @@ -218,6 +220,21 @@ static void cb_player_title_selection_changed(vlc_player_t *p_player, }); } +static void cb_player_chapter_selection_changed(vlc_player_t *p_player, + const struct vlc_player_title *p_title, size_t title_idx, + const struct vlc_player_chapter *p_new_chapter, size_t new_chapter_idx, + void *p_data) +{ + VLC_UNUSED(p_player); + VLC_UNUSED(p_title); + VLC_UNUSED(title_idx); + VLC_UNUSED(p_new_chapter); + dispatch_async(dispatch_get_main_queue(), ^{ + VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data; + [playerController selectedChapterChanged:new_chapter_idx]; + }); +} + static void cb_player_teletext_menu_availability_changed(vlc_player_t *p_player, bool hasTeletextMenu, void *p_data) { VLC_UNUSED(p_player); @@ -422,7 +439,7 @@ static const struct vlc_player_cbs player_callbacks = { NULL, //cb_player_program_selection_changed, cb_player_titles_changed, cb_player_title_selection_changed, - NULL, //cb_player_chapter_selection_changed, + cb_player_chapter_selection_changed, cb_player_teletext_menu_availability_changed, cb_player_teletext_enabled_changed, cb_player_teletext_page_changed, @@ -1095,6 +1112,54 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = { return vlc_player_title_list_GetCount(_currentTitleList); } +- (void)selectedChapterChanged:(size_t)chapterIndex +{ + _selectedChapterIndex = chapterIndex; + [_defaultNotificationCenter postNotificationName:VLCPlayerChapterSelectionChanged + object:self]; +} + +- (void)setSelectedChapterIndex:(size_t)selectedChapterIndex +{ + vlc_player_Lock(_p_player); + vlc_player_SelectChapterIdx(_p_player, selectedChapterIndex); + vlc_player_Unlock(_p_player); +} + +- (void)selectNextChapter +{ + vlc_player_Lock(_p_player); + vlc_player_SelectNextChapter(_p_player); + vlc_player_Unlock(_p_player); +} + +- (void)selectPreviousChapter +{ + vlc_player_Lock(_p_player); + vlc_player_SelectPrevChapter(_p_player); + vlc_player_Unlock(_p_player); +} + +- (size_t)numberOfChaptersForCurrentTitle +{ + const struct vlc_player_title *p_current_title = [self selectedTitle]; + if (p_current_title == NULL) { + return 0; + } + + return p_current_title->chapter_count; +} + +- (const struct vlc_player_chapter *)chapterAtIndexForCurrentTitle:(size_t)index +{ + const struct vlc_player_title *p_current_title = [self selectedTitle]; + if (p_current_title == NULL || !p_current_title->chapter_count) { + return NULL; + } + + return &p_current_title->chapters[index]; +} + - (void)teletextAvailibilityChanged:(BOOL)hasTeletextMenu { _teletextMenuAvailable = hasTeletextMenu; _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
