VLCPlaybackInfoMediaInfoTVViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCPlaybackInfoMediaInfoTVViewController.h"
  12. #import "VLCMetadata.h"
  13. @interface VLCPlaybackInfoMediaInfoTVViewController ()
  14. @end
  15. @implementation VLCPlaybackInfoMediaInfoTVViewController
  16. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  17. {
  18. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  19. if (self) {
  20. self.title = NSLocalizedString(@"MEDIA_INFO", nil);
  21. }
  22. return self;
  23. }
  24. - (void)viewDidLoad
  25. {
  26. [super viewDidLoad];
  27. self.titleLabel.text = nil;
  28. self.metaDataLabel.text = nil;
  29. [[NSNotificationCenter defaultCenter] addObserver:self
  30. selector:@selector(updateMediaTitle)
  31. name:VLCPlaybackServicePlaybackMetadataDidChange
  32. object:nil];
  33. }
  34. - (void)viewWillAppear:(BOOL)animated
  35. {
  36. if ([UIScreen mainScreen].traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  37. UIColor *lightColor = [UIColor VLCLightTextColor];
  38. self.titleLabel.textColor = lightColor;
  39. self.metaDataLabel.textColor = lightColor;
  40. } else {
  41. UIColor *darkColor = [UIColor VLCDarkTextColor];
  42. self.titleLabel.textColor = darkColor;
  43. self.metaDataLabel.textColor = darkColor;
  44. }
  45. VLCPlaybackService *vpc = [VLCPlaybackService sharedInstance];
  46. self.titleLabel.text = vpc.metadata.title;
  47. VLCMedia *media = [vpc currentlyPlayingMedia];
  48. NSArray *mediaTrackData = media.tracksInformation;
  49. NSUInteger trackDataCount = mediaTrackData.count;
  50. NSUInteger videoWidth = 0, videoHeight = 0;
  51. NSString *videoCodec;
  52. NSString *audioCodecs;
  53. NSString *spuCodecs;
  54. for (NSUInteger x = 0; x < trackDataCount; x++) {
  55. NSDictionary *trackItem = mediaTrackData[x];
  56. NSString *trackType = trackItem[VLCMediaTracksInformationType];
  57. if ([trackType isEqualToString:VLCMediaTracksInformationTypeVideo]) {
  58. videoWidth = [trackItem[VLCMediaTracksInformationVideoWidth] unsignedIntegerValue];
  59. videoHeight = [trackItem[VLCMediaTracksInformationVideoHeight] unsignedIntegerValue];
  60. videoCodec = [VLCMedia codecNameForFourCC:[trackItem[VLCMediaTracksInformationCodec] unsignedIntValue]
  61. trackType:VLCMediaTracksInformationTypeVideo];
  62. } else if ([trackType isEqualToString:VLCMediaTracksInformationTypeAudio]) {
  63. NSString *language = trackItem[VLCMediaTracksInformationLanguage];
  64. NSString *codec = [VLCMedia codecNameForFourCC:[trackItem[VLCMediaTracksInformationCodec] unsignedIntValue]
  65. trackType:VLCMediaTracksInformationTypeAudio];
  66. if (audioCodecs) {
  67. if (language)
  68. audioCodecs = [audioCodecs stringByAppendingFormat:@", %@ — %@", language, codec];
  69. else
  70. audioCodecs = [audioCodecs stringByAppendingFormat:@", %@", codec];
  71. } else {
  72. if (language)
  73. audioCodecs = [NSString stringWithFormat:@"%@ — %@", language, codec];
  74. else
  75. audioCodecs = codec;
  76. }
  77. } else if ([trackType isEqualToString:VLCMediaTracksInformationTypeText]) {
  78. NSString *language = trackItem[VLCMediaTracksInformationLanguage];
  79. NSString *codec = [VLCMedia codecNameForFourCC:[trackItem[VLCMediaTracksInformationCodec] unsignedIntValue]
  80. trackType:VLCMediaTracksInformationTypeText];
  81. if (spuCodecs) {
  82. if (language)
  83. spuCodecs = [spuCodecs stringByAppendingFormat:@", %@ — %@", language, codec];
  84. else
  85. spuCodecs = [spuCodecs stringByAppendingFormat:@", %@", codec];
  86. } else {
  87. if (language)
  88. spuCodecs = [NSString stringWithFormat:@"%@ — %@", language, codec];
  89. else
  90. spuCodecs = codec;
  91. }
  92. }
  93. }
  94. NSString *metaDataString = @"";
  95. if (media.length.intValue > 0) {
  96. metaDataString = [NSString stringWithFormat:@"%@: %@\n",
  97. NSLocalizedString(@"DURATION", nil),
  98. media.length.verboseStringValue];
  99. }
  100. if (!vpc.metadata.isAudioOnly) {
  101. metaDataString = [metaDataString stringByAppendingFormat:@"%@: %@ (%@)\n",
  102. NSLocalizedString(@"VIDEO_DIMENSIONS", nil),
  103. [NSString stringWithFormat:NSLocalizedString(@"FORMAT_VIDEO_DIMENSIONS", nil),
  104. videoWidth, videoHeight],
  105. videoCodec];
  106. }
  107. NSInteger audioTrackCount = [vpc numberOfAudioTracks] -1; // minus fake disable track
  108. if (audioTrackCount > 0) {
  109. if (audioTrackCount > 1) {
  110. metaDataString = [metaDataString stringByAppendingFormat:NSLocalizedString(@"FORMAT_AUDIO_TRACKS", nil),
  111. audioTrackCount];
  112. } else {
  113. metaDataString = [metaDataString stringByAppendingString:NSLocalizedString(@"ONE_AUDIO_TRACK", nil)];
  114. }
  115. metaDataString = [metaDataString stringByAppendingFormat:@" (%@)\n", audioCodecs];
  116. }
  117. NSInteger spuTrackCount = [vpc numberOfVideoSubtitlesIndexes] - 1; // minus fake disable track
  118. if (spuTrackCount > 0) {
  119. if (spuTrackCount > 1) {
  120. metaDataString = [metaDataString stringByAppendingFormat:NSLocalizedString(@"FORMAT_SPU_TRACKS", nil),
  121. spuTrackCount];
  122. } else {
  123. metaDataString = [metaDataString stringByAppendingString:NSLocalizedString(@"ONE_SPU_TRACK", nil)];
  124. }
  125. metaDataString = [metaDataString stringByAppendingFormat:@" (%@)\n", spuCodecs];
  126. }
  127. self.metaDataLabel.text = metaDataString;
  128. [self.metaDataLabel sizeToFit];
  129. [super viewWillAppear:animated];
  130. }
  131. - (CGSize)preferredContentSize
  132. {
  133. return CGSizeMake(CGRectGetWidth(self.view.bounds), 31. + self.titleLabel.frame.size.height + 8. + self.metaDataLabel.frame.size.height + 82.);
  134. }
  135. - (void)updateMediaTitle
  136. {
  137. self.titleLabel.text = [VLCPlaybackService sharedInstance].metadata.title;
  138. }
  139. @end