Commit 7153bd37 authored by Carola Nitz's avatar Carola Nitz

VLCTrackSelectorView: remove knowledge of mediaplayer

parent 9bd1fc99
Pipeline #227 passed with stage
in 0 seconds
......@@ -67,7 +67,14 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
@property (nonatomic, readwrite) float playbackRate; // default = 1.0
@property (nonatomic, readwrite) float audioDelay; // in seconds, default = 0.0
@property (nonatomic, readwrite) float subtitleDelay; // in seconds, default = 0.0
@property (nonatomic, readonly) BOOL currentMediaHasChapters;
@property (readonly) NSInteger indexOfCurrentAudioTrack;
@property (readonly) NSInteger indexOfCurrentSubtitleTrack;
@property (readonly) NSInteger indexOfCurrentTitle;
@property (readonly) NSInteger indexOfCurrentChapter;
@property (readonly) NSInteger numberOfAudioTracks;
@property (readonly) NSInteger numberOfVideoSubtitlesIndexes;
@property (readonly) NSInteger numberOfTitles;
@property (readonly) NSInteger numberOfChaptersForCurrentTitle;
@property (nonatomic, readonly) BOOL currentMediaHasTrackToChooseFrom;
@property (nonatomic, readwrite) BOOL fullscreenSessionRequested;
@property (readonly) NSNumber *playbackTime;
......@@ -81,6 +88,16 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
- (void)playPause;
- (void)next;
- (void)previous;
- (NSString *)audioTrackNameAtIndex:(NSInteger)index;
- (NSString *)videoSubtitleNameAtIndex:(NSInteger)index;
- (NSDictionary *)titleDescriptionsDictAtIndex:(NSInteger)index;
- (NSDictionary *)chapterDescriptionsDictAtIndex:(NSInteger)index;
- (void)selectAudioTrackAtIndex:(NSInteger)index;
- (void)selectVideoSubtitleAtIndex:(NSInteger)index;
- (void)selectTitleAtIndex:(NSInteger)index;
- (void)selectChapterAtIndex:(NSInteger)index;
- (void)switchAspectRatio;
- (BOOL)updateViewpoint:(CGFloat)yaw pitch:(CGFloat)pitch roll:(CGFloat)roll fov:(CGFloat)fov absolute:(BOOL)absolute;
- (NSInteger)currentMediaProjection;
......
......@@ -479,6 +479,106 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
return _mediaPlayer.currentVideoSubTitleDelay/1000000.;
}
- (NSInteger)indexOfCurrentAudioTrack
{
return [_mediaPlayer.audioTrackIndexes indexOfObject:@(_mediaPlayer.currentAudioTrackIndex)];
}
- (NSInteger)indexOfCurrentSubtitleTrack
{
return [_mediaPlayer.videoSubTitlesIndexes indexOfObject:@(_mediaPlayer.currentVideoSubTitleIndex)];
}
- (NSInteger)indexOfCurrentChapter
{
return _mediaPlayer.currentChapterIndex;
}
- (NSInteger)indexOfCurrentTitle
{
return _mediaPlayer.currentTitleIndex;
}
- (NSInteger)numberOfAudioTracks
{
return _mediaPlayer.audioTrackIndexes.count;
}
- (NSInteger)numberOfVideoSubtitlesIndexes
{
return _mediaPlayer.videoSubTitlesIndexes.count;
}
- (NSInteger)numberOfTitles
{
return [_mediaPlayer numberOfTitles];
}
- (NSInteger)numberOfChaptersForCurrentTitle
{
return [_mediaPlayer numberOfChaptersForTitle:_mediaPlayer.currentTitleIndex];
}
- (NSString *)videoSubtitleNameAtIndex:(NSInteger)index
{
if (index >= 0 && index < _mediaPlayer.videoSubTitlesNames.count)
return _mediaPlayer.videoSubTitlesNames[index];
return nil;
}
- (NSString *)audioTrackNameAtIndex:(NSInteger)index
{
if (index >= 0 && index < _mediaPlayer.audioTrackNames.count)
return _mediaPlayer.audioTrackNames[index];
return nil;
}
- (NSDictionary *)titleDescriptionsDictAtIndex:(NSInteger)index
{
if (index >= 0 && index < _mediaPlayer.titleDescriptions.count)
return _mediaPlayer.titleDescriptions[index];
return nil;
}
- (NSDictionary *)chapterDescriptionsDictAtIndex:(NSInteger)index
{
NSArray *chapterDescriptions = [_mediaPlayer chapterDescriptionsOfTitle:_mediaPlayer.currentTitleIndex];
if (index >= 0 && index < chapterDescriptions.count)
return chapterDescriptions[index];
return nil;
}
- (void)selectAudioTrackAtIndex:(NSInteger)index
{
if (index >= 0 && index < _mediaPlayer.audioTrackIndexes.count) {
//we can cast this cause we won't have more than 2 million audiotracks
_mediaPlayer.currentAudioTrackIndex = [_mediaPlayer.audioTrackIndexes[index] intValue];
}
}
- (void)selectVideoSubtitleAtIndex:(NSInteger)index
{
if (index >= 0 && index < _mediaPlayer.videoSubTitlesIndexes.count) {
_mediaPlayer.currentVideoSubTitleIndex = [_mediaPlayer.videoSubTitlesIndexes[index] intValue];
}
}
- (void)selectTitleAtIndex:(NSInteger)index
{
if (index >= 0 && index < [_mediaPlayer numberOfTitles]) {
//we can cast this cause we won't have more than 2 million titles
_mediaPlayer.currentTitleIndex = (int)index;
}
}
- (void)selectChapterAtIndex:(NSInteger)index
{
if (index >= 0 && index < [self numberOfChaptersForCurrentTitle]) {
//we can cast this cause we won't have more than 2 million chapters
_mediaPlayer.currentChapterIndex = (int)index;
}
}
- (void)mediaPlayerStateChanged:(NSNotification *)aNotification
{
VLCMediaPlayerState currentState = _mediaPlayer.state;
......@@ -1008,6 +1108,7 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
{
self.playbackRate = playbackRate;
}
#pragma mark - helpers
- (NSDictionary *)mediaOptionsDictionary
......
......@@ -82,24 +82,24 @@
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSInteger ret = 0;
VLCMediaPlayer *mediaPlayer = [VLCPlaybackController sharedInstance].mediaPlayer;
NSInteger sections = 0;
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance];
if (_switchingTracksNotChapters) {
if (mediaPlayer.audioTrackIndexes.count > 2)
ret++;
if([playbackController numberOfAudioTracks] > 2)
sections++;
if (mediaPlayer.videoSubTitlesIndexes.count > 1)
ret++;
if ([playbackController numberOfVideoSubtitlesIndexes] > 1)
sections++;
} else {
if ([mediaPlayer numberOfTitles] > 1)
ret++;
if ([playbackController numberOfTitles] > 1)
sections++;
if ([mediaPlayer numberOfChaptersForTitle:mediaPlayer.currentTitleIndex] > 1)
ret++;
if ([playbackController numberOfChaptersForCurrentTitle] > 1)
sections++;
}
return ret;
return sections;
}
- (void)updateView
......@@ -119,19 +119,19 @@
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
VLCMediaPlayer *mediaPlayer = [VLCPlaybackController sharedInstance].mediaPlayer;
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance];
if (_switchingTracksNotChapters == YES) {
if (mediaPlayer.audioTrackIndexes.count > 2 && section == 0)
if (_switchingTracksNotChapters) {
if ([playbackController numberOfAudioTracks] > 2 && section == 0)
return NSLocalizedString(@"CHOOSE_AUDIO_TRACK", nil);
if (mediaPlayer.videoSubTitlesIndexes.count > 1)
if ([playbackController numberOfVideoSubtitlesIndexes] > 1)
return NSLocalizedString(@"CHOOSE_SUBTITLE_TRACK", nil);
} else {
if ([mediaPlayer numberOfTitles] > 1 && section == 0)
if ([playbackController numberOfTitles] > 1 && section == 0)
return NSLocalizedString(@"CHOOSE_TITLE", nil);
if ([mediaPlayer numberOfChaptersForTitle:mediaPlayer.currentTitleIndex] > 1)
if ([playbackController numberOfChaptersForCurrentTitle] > 1)
return NSLocalizedString(@"CHOOSE_CHAPTER", nil);
}
......@@ -140,67 +140,52 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
VLCTrackSelectorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TRACK_SELECTOR_TABLEVIEW_CELL];
VLCTrackSelectorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TRACK_SELECTOR_TABLEVIEW_CELL forIndexPath:indexPath];
if (!cell) {
cell = [[VLCTrackSelectorTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TRACK_SELECTOR_TABLEVIEW_CELL];
}
NSInteger row = indexPath.row;
NSInteger section = indexPath.section;
VLCMediaPlayer *mediaPlayer = [VLCPlaybackController sharedInstance].mediaPlayer;
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance];
if (_switchingTracksNotChapters) {
NSArray *indexArray;
NSString *trackName;
if ([mediaPlayer numberOfAudioTracks] > 2 && section == 0) {
indexArray = mediaPlayer.audioTrackIndexes;
if ([indexArray indexOfObject:[NSNumber numberWithInt:mediaPlayer.currentAudioTrackIndex]] == row)
if ([playbackController numberOfAudioTracks] > 2 && section == 0) {
if ([playbackController indexOfCurrentAudioTrack] == row) {
[cell setShowsCurrentTrack];
NSArray *audioTrackNames = mediaPlayer.audioTrackNames;
if (row < audioTrackNames.count) {
trackName = audioTrackNames[row];
}
} else {
indexArray = mediaPlayer.videoSubTitlesIndexes;
if ([indexArray indexOfObject:[NSNumber numberWithInt:mediaPlayer.currentVideoSubTitleIndex]] == row)
trackName = [playbackController audioTrackNameAtIndex:row];
} else {
if ([playbackController indexOfCurrentSubtitleTrack] == row) {
[cell setShowsCurrentTrack];
NSArray *videoSubtitlesNames = mediaPlayer.videoSubTitlesNames;
if (row < videoSubtitlesNames.count) {
trackName = mediaPlayer.videoSubTitlesNames[row];
}
trackName = [playbackController videoSubtitleNameAtIndex:row];
}
if (trackName != nil) {
if ([trackName isEqualToString:@"Disable"]) {
cell.textLabel.text = NSLocalizedString(@"DISABLE_LABEL", nil);
} else {
cell.textLabel.text = trackName;
}
if ([trackName isEqualToString:@"Disable"]) {
cell.textLabel.text = NSLocalizedString(@"DISABLE_LABEL", nil);
} else {
cell.textLabel.text = trackName;
}
} else {
if ([mediaPlayer numberOfTitles] > 1 && section == 0) {
NSArray *titleDescriptions = mediaPlayer.titleDescriptions;
if (row < titleDescriptions.count) {
NSDictionary *description = titleDescriptions[row];
if ([playbackController numberOfTitles] > 1 && section == 0) {
NSDictionary *description = [playbackController titleDescriptionsDictAtIndex:row];
if(description != nil) {
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", description[VLCTitleDescriptionName], [[VLCTime timeWithNumber:description[VLCTitleDescriptionDuration]] stringValue]];
}
if (row == mediaPlayer.currentTitleIndex)
if (row == [playbackController indexOfCurrentTitle]) {
[cell setShowsCurrentTrack];
}
} else {
NSArray *chapterDescriptions = [mediaPlayer chapterDescriptionsOfTitle:mediaPlayer.currentTitleIndex];
if (row < chapterDescriptions.count) {
NSDictionary *description = chapterDescriptions[row];
NSDictionary *description = [playbackController chapterDescriptionsDictAtIndex:row];
if (description != nil)
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", description[VLCChapterDescriptionName], [[VLCTime timeWithNumber:description[VLCChapterDescriptionDuration]] stringValue]];
}
if (row == mediaPlayer.currentChapterIndex)
[cell setShowsCurrentTrack];
}
if (row == [playbackController indexOfCurrentChapter])
[cell setShowsCurrentTrack];
}
return cell;
......@@ -208,20 +193,18 @@
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
VLCMediaPlayer *mediaPlayer = [VLCPlaybackController sharedInstance].mediaPlayer;
if (_switchingTracksNotChapters == YES) {
NSInteger audioTrackCount = mediaPlayer.audioTrackIndexes.count;
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance];
if (audioTrackCount > 2 && section == 0)
return audioTrackCount;
if (_switchingTracksNotChapters) {
if ([playbackController numberOfAudioTracks] > 2 && section == 0)
return [playbackController numberOfAudioTracks];
return mediaPlayer.videoSubTitlesIndexes.count;
return [playbackController numberOfVideoSubtitlesIndexes];
} else {
if ([mediaPlayer numberOfTitles] > 1 && section == 0)
return [mediaPlayer numberOfTitles];
if ([playbackController numberOfTitles] > 1 && section == 0)
return [playbackController numberOfTitles];
else
return [mediaPlayer numberOfChaptersForTitle:mediaPlayer.currentTitleIndex];
return [playbackController numberOfChaptersForCurrentTitle];
}
}
......@@ -229,25 +212,20 @@
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSInteger index = indexPath.row;
VLCMediaPlayer *mediaPlayer = [VLCPlaybackController sharedInstance].mediaPlayer;
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance];
if (_switchingTracksNotChapters) {
NSArray *indexArray;
if (mediaPlayer.audioTrackIndexes.count > 2 && indexPath.section == 0) {
indexArray = mediaPlayer.audioTrackIndexes;
if (index <= indexArray.count)
mediaPlayer.currentAudioTrackIndex = [indexArray[index] intValue];
if ([playbackController numberOfAudioTracks] > 2 && indexPath.section == 0) {
[playbackController selectAudioTrackAtIndex:index];
} else {
indexArray = mediaPlayer.videoSubTitlesIndexes;
if (index <= indexArray.count)
mediaPlayer.currentVideoSubTitleIndex = [indexArray[index] intValue];
} else if (index <= [playbackController numberOfVideoSubtitlesIndexes]) {
[playbackController selectVideoSubtitleAtIndex:index];
}
} else {
if ([mediaPlayer numberOfTitles] > 1 && indexPath.section == 0)
mediaPlayer.currentTitleIndex = (int)index;
if ([playbackController numberOfTitles] > 1 && indexPath.section == 0)
[playbackController selectTitleAtIndex:index];
else
mediaPlayer.currentChapterIndex = (int)index;
[playbackController selectChapterAtIndex:index];
}
self.alpha = 1.0f;
......
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