VLCAudio.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*****************************************************************************
  2. * VLCAudio.m: VLCKit.framework VLCAudio implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Faustino E. Osuna
  5. * Copyright (C) 2007 the VideoLAN team
  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
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 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 General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, 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. - (id)init
  35. {
  36. return nil;
  37. }
  38. - (id)initWithLibrary:(VLCLibrary *)aLibrary
  39. {
  40. if (![library audio] && (self = [super init]))
  41. {
  42. library = aLibrary;
  43. [library setAudio:self];
  44. }
  45. return self;
  46. }
  47. - (void)setMute:(BOOL)value
  48. {
  49. libvlc_audio_set_mute([library instance], value);
  50. }
  51. - (BOOL)isMuted
  52. {
  53. return libvlc_audio_get_mute([library instance]);
  54. }
  55. - (void)setVolume:(int)value
  56. {
  57. if (value < VOLUME_MIN)
  58. value = VOLUME_MIN;
  59. else if (value > VOLUME_MAX)
  60. value = VOLUME_MAX;
  61. libvlc_audio_set_volume([library instance], value, NULL);
  62. }
  63. - (void)volumeUp
  64. {
  65. int tempVolume = [self volume] + VOLUME_STEP;
  66. if (tempVolume > VOLUME_MAX)
  67. tempVolume = VOLUME_MAX;
  68. else if (tempVolume < VOLUME_MIN)
  69. tempVolume = VOLUME_MIN;
  70. [self setVolume: tempVolume];
  71. }
  72. - (void)volumeDown
  73. {
  74. int tempVolume = [self volume] - VOLUME_STEP;
  75. if (tempVolume > VOLUME_MAX)
  76. tempVolume = VOLUME_MAX;
  77. else if (tempVolume < VOLUME_MIN)
  78. tempVolume = VOLUME_MIN;
  79. [self setVolume: tempVolume];
  80. }
  81. - (int)volume
  82. {
  83. return libvlc_audio_get_volume([library instance]);
  84. }
  85. @end