VLCAudio.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 * 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. - (id)init
  42. {
  43. return nil;
  44. }
  45. - (id)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. [super dealloc];
  58. }
  59. - (void)setMute:(BOOL)value
  60. {
  61. libvlc_audio_set_mute([self instance], value);
  62. }
  63. - (BOOL)isMuted
  64. {
  65. return libvlc_audio_get_mute([self instance]);
  66. }
  67. - (void)setVolume:(NSUInteger)value
  68. {
  69. if (value < VOLUME_MIN)
  70. value = VOLUME_MIN;
  71. else if (value > VOLUME_MAX)
  72. value = VOLUME_MAX;
  73. libvlc_audio_set_volume([self instance], value);
  74. }
  75. - (void)volumeUp
  76. {
  77. NSUInteger tempVolume = [self volume] + VOLUME_STEP;
  78. if (tempVolume > VOLUME_MAX)
  79. tempVolume = VOLUME_MAX;
  80. else if (tempVolume < VOLUME_MIN)
  81. tempVolume = VOLUME_MIN;
  82. [self setVolume: tempVolume];
  83. }
  84. - (void)volumeDown
  85. {
  86. NSUInteger tempVolume = [self volume] - VOLUME_STEP;
  87. if (tempVolume > VOLUME_MAX)
  88. tempVolume = VOLUME_MAX;
  89. else if (tempVolume < VOLUME_MIN)
  90. tempVolume = VOLUME_MIN;
  91. [self setVolume: tempVolume];
  92. }
  93. - (NSUInteger)volume
  94. {
  95. return libvlc_audio_get_volume([self instance]);
  96. }
  97. @end