VLCAudio.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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)setVolume:(int)value
  76. {
  77. if (value < VOLUME_MIN)
  78. value = VOLUME_MIN;
  79. else if (value > VOLUME_MAX)
  80. value = VOLUME_MAX;
  81. libvlc_audio_set_volume([self instance], value);
  82. }
  83. - (void)volumeUp
  84. {
  85. int tempVolume = [self volume] + VOLUME_STEP;
  86. if (tempVolume > VOLUME_MAX)
  87. tempVolume = VOLUME_MAX;
  88. else if (tempVolume < VOLUME_MIN)
  89. tempVolume = VOLUME_MIN;
  90. [self setVolume: tempVolume];
  91. }
  92. - (void)volumeDown
  93. {
  94. int tempVolume = [self volume] - VOLUME_STEP;
  95. if (tempVolume > VOLUME_MAX)
  96. tempVolume = VOLUME_MAX;
  97. else if (tempVolume < VOLUME_MIN)
  98. tempVolume = VOLUME_MIN;
  99. [self setVolume: tempVolume];
  100. }
  101. - (int)volume
  102. {
  103. return libvlc_audio_get_volume([self instance]);
  104. }
  105. @end