Commit 787f5e46 authored by Felix Paul Kühne's avatar Felix Paul Kühne

expose expanded title and chapter description API

parent 9bf1c2ea
......@@ -2,8 +2,8 @@
* VLCMediaPlayer.h: VLCKit.framework VLCMediaPlayer header
*****************************************************************************
* Copyright (C) 2007-2009 Pierre d'Herbemont
* Copyright (C) 2007-2014 VLC authors and VideoLAN
* Copyright (C) 2009-2014 Felix Paul Kühne
* Copyright (C) 2007-2015 VLC authors and VideoLAN
* Copyright (C) 2009-2015 Felix Paul Kühne
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
......@@ -358,7 +358,20 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
@property (readwrite) int currentChapterIndex;
- (void)previousChapter;
- (void)nextChapter;
- (NSArray *)chaptersForTitleIndex:(int)titleIndex;
- (NSArray *)chaptersForTitleIndex:(int)titleIndex __attribute__((deprecated));
extern NSString *const VLCChapterDescriptionName;
extern NSString *const VLCChapterDescriptionTimeOffset;
extern NSString *const VLCChapterDescriptionDuration;
/**
* chapter descriptions
* an array of all chapters of the given title including information about
* chapter name, time offset and duration
* \note if no title value is provided, information about the chapters of the current title is returned
* \return array describing the titles in details
*/
- (NSArray *)chapterDescriptionsOfTitle:(int)titleIndex;
/**
* Title selection and enumeration
......@@ -366,7 +379,25 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
*/
@property (readwrite) int currentTitleIndex;
@property (readonly) NSUInteger countOfTitles;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *titles;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *titles __attribute__((deprecated));
extern NSString *const VLCTitleDescriptionName;
extern NSString *const VLCTitleDescriptionDuration;
extern NSString *const VLCTitleDescriptionIsMenu;
/**
* title descriptions
* an array of all titles of the current media including information
* of name, duration and potential menu state
* \return array describing the titles in details
*/
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *titleDescriptions;
/**
* the title with the longest duration
* \return int matching the title index
*/
@property (readonly) int indexOfLongestTitle;
/* Audio Options */
......
Version 3.0.0:
--------------
New APIs:
- VLCMediaPlayer
- added properties: titleDescriptions, indexOfLongestTitle
- added selector: chaptersForTitleIndex:
Deprecated APIs:
- VLCMediaPlayer
- titles, chaptersForTitleIndex:
Version 2.2.2:
--------------
New APIs:
......
......@@ -2,8 +2,8 @@
* VLCMediaPlayer.m: VLCKit.framework VLCMediaPlayer implementation
*****************************************************************************
* Copyright (C) 2007-2009 Pierre d'Herbemont
* Copyright (C) 2007-2014 VLC authors and VideoLAN
* Partial Copyright (C) 2009-2014 Felix Paul Kühne
* Copyright (C) 2007-2015 VLC authors and VideoLAN
* Partial Copyright (C) 2009-2015 Felix Paul Kühne
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
......@@ -48,8 +48,18 @@
#include <vlc/vlc.h>
/* Notification Messages */
NSString *const VLCMediaPlayerTimeChanged = @"VLCMediaPlayerTimeChanged";
NSString *const VLCMediaPlayerStateChanged = @"VLCMediaPlayerStateChanged";
NSString *const VLCMediaPlayerTimeChanged = @"VLCMediaPlayerTimeChanged";
NSString *const VLCMediaPlayerStateChanged = @"VLCMediaPlayerStateChanged";
/* title keys */
NSString *const VLCTitleDescriptionName = @"VLCTitleDescriptionName";
NSString *const VLCTitleDescriptionDuration = @"VLCTitleDescriptionDuration";
NSString *const VLCTitleDescriptionIsMenu = @"VLCTitleDescriptionIsMenu";
/* chapter keys */
NSString *const VLCChapterDescriptionName = @"VLCChapterDescriptionName";
NSString *const VLCChapterDescriptionTimeOffset = @"VLCChapterDescriptionTimeOffset";
NSString *const VLCChapterDescriptionDuration = @"VLCChapterDescriptionDuration";
NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state)
{
......@@ -711,6 +721,91 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
return [NSArray arrayWithArray: tempArray];
}
- (NSArray *)titleDescriptions
{
libvlc_title_description_t **titleInfo;
int numberOfTitleDescriptions = libvlc_media_player_get_full_title_descriptions(_playerInstance, &titleInfo);
if (numberOfTitleDescriptions < 0)
return [NSArray array];
if (numberOfTitleDescriptions == 0) {
libvlc_title_descriptions_release(titleInfo, numberOfTitleDescriptions);
return [NSArray array];
}
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:numberOfChapterDescriptions];
for (int i = 0; i < numberOfTitleDescriptions; i++) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithLongLong:titleInfo[i]->i_duration],
VLCTitleDescriptionDuration,
@(titleInfo[i]->b_menu),
VLCTitleDescriptionIsMenu,
nil];
if (titleInfo[i]->psz_name != NULL)
dictionary[VLCTitleDescriptionName] = [NSString stringWithUTF8String:titleInfo[i]->psz_name];
[array addObject:[NSDictionary dictionaryWithDictionary:dictionary]];
}
libvlc_title_descriptions_release(titleInfo, numberOfTitleDescriptions);
return [NSArray arrayWithArray:array];
}
- (int)indexOfLongestTitle
{
NSArray *titles = [self titleDescriptions];
NSUInteger titleCount = titles.count;
int currentlyFoundTitle = 0;
int64_t currentlySelectedDuration = 0;
int64_t randomTitleDuration = 0;
for (int x = 0; x < titleCount; x++) {
randomTitleDuration = [[titles[x] valueForKey:VLCTitleDescriptionDuration] longLongValue];
if (randomTitleDuration > currentlySelectedDuration) {
currentlySelectedDuration = randomTitleDuration;
currentlyFoundTitle = x;
}
}
return currentlyFoundTitle;
}
- (NSArray *)chapterDescriptionsOfTitle:(int)titleIndex
{
libvlc_chapter_description_t **chapterDescriptions;
int numberOfChapterDescriptions = libvlc_media_player_get_full_chapter_descriptions(_playerInstance,
titleIndex,
&chapterDescriptions);
if (numberOfChapterDescriptions < 0)
return [NSArray array];
if (numberOfChapterDescriptions == 0) {
libvlc_chapter_descriptions_release(chapterDescriptions, numberOfChapterDescriptions);
return [NSArray array];
}
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:numberOfChapterDescriptions];
for (int i = 0; i < numberOfChapterDescriptions; i++) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithLongLong:chapterDescriptions[i]->i_duration],
VLCChapterDescriptionDuration,
[NSNumber numberWithLongLong:chapterDescriptions[i]->i_time_offset],
VLCChapterDescriptionTimeOffset,
nil];
if (chapterDescriptions[i]->psz_name != NULL)
dictionary[VLCChapterDescriptionName] = [NSString stringWithUTF8String:chapterDescriptions[i]->psz_name];
[array addObject:[NSDictionary dictionaryWithDictionary:dictionary]];
}
libvlc_chapter_descriptions_release(chapterDescriptions, numberOfChapterDescriptions);
return [NSArray arrayWithArray:array];
}
#pragma mark -
#pragma mark Audio tracks
- (void)setCurrentAudioTrackIndex:(int)value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment