VLCAudio.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. - (BOOL)isMuted
  68. {
  69. return libvlc_audio_get_mute([self instance]);
  70. }
  71. - (void)setPassthrough:(BOOL)passthrough
  72. {
  73. if (passthrough) {
  74. libvlc_audio_output_device_set([self instance], NULL, "encoded");
  75. } else {
  76. libvlc_audio_output_device_set([self instance], NULL, "pcm");
  77. }
  78. }
  79. - (BOOL)passthrough
  80. {
  81. char *deviceIdentifier = libvlc_audio_output_device_get([self instance]);
  82. if (deviceIdentifier != NULL) {
  83. if (!strcmp(deviceIdentifier, "encoded")) {
  84. return YES;
  85. }
  86. free(deviceIdentifier);
  87. }
  88. return NO;
  89. }
  90. - (void)setVolume:(int)value
  91. {
  92. if (value < VOLUME_MIN)
  93. value = VOLUME_MIN;
  94. else if (value > VOLUME_MAX)
  95. value = VOLUME_MAX;
  96. libvlc_audio_set_volume([self instance], value);
  97. }
  98. - (void)volumeUp
  99. {
  100. int tempVolume = [self volume] + VOLUME_STEP;
  101. if (tempVolume > VOLUME_MAX)
  102. tempVolume = VOLUME_MAX;
  103. [self setVolume: tempVolume];
  104. }
  105. - (void)volumeDown
  106. {
  107. int tempVolume = [self volume] - VOLUME_STEP;
  108. if (tempVolume < VOLUME_MIN)
  109. tempVolume = VOLUME_MIN;
  110. [self setVolume: tempVolume];
  111. }
  112. - (int)volume
  113. {
  114. return libvlc_audio_get_volume([self instance]);
  115. }
  116. @end