VLCAudio.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*****************************************************************************
  2. * VLCAudio.m: VLCKit.framework VLCAudio implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Faustino E. Osuna
  5. * Copyright (C) 2007 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. /* Notification Messages */
  30. NSString *const VLCMediaPlayerVolumeChanged = @"VLCMediaPlayerVolumeChanged";
  31. /* libvlc event callback */
  32. // TODO: Callbacks
  33. @implementation VLCAudio
  34. /**
  35. * Use this method instead of instance directly as this one is type checked.
  36. */
  37. - (libvlc_media_player_t *)instance
  38. {
  39. return instance;
  40. }
  41. - (instancetype)init
  42. {
  43. return nil;
  44. }
  45. - (instancetype)initWithMediaPlayer:(VLCMediaPlayer *)mediaPlayer
  46. {
  47. self = [super init];
  48. if (!self)
  49. return nil;
  50. instance = [mediaPlayer libVLCMediaPlayer];
  51. libvlc_media_player_retain([self instance]);
  52. return self;
  53. }
  54. - (void) dealloc
  55. {
  56. libvlc_media_player_release([self instance]);
  57. }
  58. - (void)setMute:(BOOL)value
  59. {
  60. libvlc_audio_set_mute([self instance], value);
  61. }
  62. - (BOOL)isMuted
  63. {
  64. return libvlc_audio_get_mute([self instance]);
  65. }
  66. - (void)setVolume:(int)value
  67. {
  68. if (value < VOLUME_MIN)
  69. value = VOLUME_MIN;
  70. else if (value > VOLUME_MAX)
  71. value = VOLUME_MAX;
  72. libvlc_audio_set_volume([self instance], value);
  73. }
  74. - (void)volumeUp
  75. {
  76. int tempVolume = [self volume] + VOLUME_STEP;
  77. if (tempVolume > VOLUME_MAX)
  78. tempVolume = VOLUME_MAX;
  79. else if (tempVolume < VOLUME_MIN)
  80. tempVolume = VOLUME_MIN;
  81. [self setVolume: tempVolume];
  82. }
  83. - (void)volumeDown
  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. - (int)volume
  93. {
  94. return libvlc_audio_get_volume([self instance]);
  95. }
  96. @end