VLCAudio.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*****************************************************************************
  2. * VLCAudio.m: VLCKit.framework VLCAudio implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Faustino E. Osuna
  5. * Copyright (C) 2007, 2014 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Faustino E. Osuna <enrique.osuna # gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import "VLCAudio.h"
  25. #import "VLCLibVLCBridging.h"
  26. #define VOLUME_STEP 6
  27. #define VOLUME_MAX 200
  28. #define VOLUME_MIN 0
  29. @interface VLCAudio ()
  30. {
  31. void *_instance;
  32. }
  33. @end
  34. /* Notification Messages */
  35. NSString *const VLCMediaPlayerVolumeChanged = @"VLCMediaPlayerVolumeChanged";
  36. /* libvlc event callback */
  37. // TODO: Callbacks
  38. @implementation VLCAudio
  39. /**
  40. * Use this method instead of instance directly as this one is type checked.
  41. */
  42. - (libvlc_media_player_t *)instance
  43. {
  44. return _instance;
  45. }
  46. - (instancetype)init
  47. {
  48. return nil;
  49. }
  50. - (instancetype)initWithMediaPlayer:(VLCMediaPlayer *)mediaPlayer
  51. {
  52. self = [super init];
  53. if (!self)
  54. return nil;
  55. _instance = [mediaPlayer libVLCMediaPlayer];
  56. libvlc_media_player_retain([self instance]);
  57. return self;
  58. }
  59. - (void) dealloc
  60. {
  61. libvlc_media_player_release([self instance]);
  62. }
  63. - (void)setMuted:(BOOL)value
  64. {
  65. libvlc_audio_set_mute([self instance], value);
  66. }
  67. - (void)setMute:(BOOL)value
  68. {
  69. [self setMuted:value];
  70. }
  71. - (BOOL)isMuted
  72. {
  73. return libvlc_audio_get_mute([self instance]);
  74. }
  75. - (void)setPassthrough:(BOOL)passthrough
  76. {
  77. if (passthrough) {
  78. libvlc_audio_output_device_set([self instance], NULL, "encoded");
  79. } else {
  80. libvlc_audio_output_device_set([self instance], NULL, "pcm");
  81. }
  82. }
  83. - (BOOL)passthrough
  84. {
  85. char *deviceIdentifier = libvlc_audio_output_device_get([self instance]);
  86. if (deviceIdentifier != NULL) {
  87. if (!strcmp(deviceIdentifier, "encoded")) {
  88. return YES;
  89. }
  90. free(deviceIdentifier);
  91. }
  92. return NO;
  93. }
  94. - (void)setVolume:(int)value
  95. {
  96. if (value < VOLUME_MIN)
  97. value = VOLUME_MIN;
  98. else if (value > VOLUME_MAX)
  99. value = VOLUME_MAX;
  100. libvlc_audio_set_volume([self instance], value);
  101. }
  102. - (void)volumeUp
  103. {
  104. int tempVolume = [self volume] + VOLUME_STEP;
  105. if (tempVolume > VOLUME_MAX)
  106. tempVolume = VOLUME_MAX;
  107. [self setVolume: tempVolume];
  108. }
  109. - (void)volumeDown
  110. {
  111. int tempVolume = [self volume] - VOLUME_STEP;
  112. if (tempVolume < VOLUME_MIN)
  113. tempVolume = VOLUME_MIN;
  114. [self setVolume: tempVolume];
  115. }
  116. - (int)volume
  117. {
  118. return libvlc_audio_get_volume([self instance]);
  119. }
  120. @end