VLCMediaListPlayer.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*****************************************************************************
  2. * VLCMediaListPlayer.m: VLCKit.framework VLCMediaListPlayer implementation
  3. *****************************************************************************
  4. * Copyright (C) 2009 Pierre d'Herbemont
  5. * Partial Copyright (C) 2009 Felix Paul Kühne
  6. * Copyright (C) 2009 the VideoLAN team
  7. * $Id$
  8. *
  9. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  10. * Felix Paul Kühne <fkuehne # videolan.org
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  25. *****************************************************************************/
  26. #import "VLCMediaListPlayer.h"
  27. #import "VLCMedia.h"
  28. #import "VLCMediaPlayer.h"
  29. #import "VLCMediaList.h"
  30. #import "VLCLibVLCBridging.h"
  31. @implementation VLCMediaListPlayer
  32. - (id)init
  33. {
  34. if (self = [super init])
  35. {
  36. _mediaPlayer = [[VLCMediaPlayer alloc] init];
  37. libvlc_exception_t ex;
  38. libvlc_exception_init(&ex);
  39. instance = libvlc_media_list_player_new([VLCLibrary sharedInstance], &ex);
  40. catch_exception(&ex);
  41. libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer]);
  42. }
  43. return self;
  44. }
  45. - (void)dealloc
  46. {
  47. libvlc_media_list_player_release(instance);
  48. [_mediaPlayer release];
  49. [_rootMedia release];
  50. [_mediaList release];
  51. [super dealloc];
  52. }
  53. - (VLCMediaPlayer *)mediaPlayer
  54. {
  55. return _mediaPlayer;
  56. }
  57. - (void)setMediaList:(VLCMediaList *)mediaList
  58. {
  59. if (_mediaList == mediaList)
  60. return;
  61. [_mediaList release];
  62. _mediaList = [mediaList retain];
  63. libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList]);
  64. [self willChangeValueForKey:@"rootMedia"];
  65. [_rootMedia release];
  66. _rootMedia = nil;
  67. [self didChangeValueForKey:@"rootMedia"];
  68. }
  69. - (VLCMediaList *)mediaList
  70. {
  71. return _mediaList;
  72. }
  73. - (void)setRootMedia:(VLCMedia *)media
  74. {
  75. if (_rootMedia == media)
  76. return;
  77. [_rootMedia release];
  78. _rootMedia = nil;
  79. VLCMediaList *mediaList = [[VLCMediaList alloc] init];
  80. if (media)
  81. [mediaList addMedia:media];
  82. // This will clean rootMedia
  83. [self setMediaList:mediaList];
  84. // Thus set rootMedia here.
  85. _rootMedia = [media retain];
  86. [mediaList release];
  87. }
  88. - (VLCMedia *)rootMedia
  89. {
  90. return _rootMedia;
  91. }
  92. - (void)playMedia:(VLCMedia *)media
  93. {
  94. libvlc_exception_t ex;
  95. libvlc_exception_init(&ex);
  96. libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
  97. catch_exception(&ex);
  98. }
  99. - (void)play
  100. {
  101. libvlc_exception_t ex;
  102. libvlc_exception_init(&ex);
  103. libvlc_media_list_player_play(instance, &ex);
  104. catch_exception(&ex);
  105. }
  106. - (void)stop
  107. {
  108. libvlc_media_list_player_stop(instance);
  109. }
  110. - (void)setRepeatMode:(VLCRepeatMode)repeatMode
  111. {
  112. libvlc_playback_mode_t mode;
  113. switch (repeatMode) {
  114. case VLCRepeatAllItems:
  115. mode = libvlc_playback_mode_loop;
  116. break;
  117. case VLCDoNotRepeat:
  118. mode = libvlc_playback_mode_default;
  119. break;
  120. case VLCRepeatCurrentItem:
  121. mode = libvlc_playback_mode_repeat;
  122. break;
  123. default:
  124. NSAssert(0, @"Should not be reached");
  125. break;
  126. }
  127. libvlc_media_list_player_set_playback_mode(instance, mode);
  128. _repeatMode = repeatMode;
  129. }
  130. - (VLCRepeatMode)repeatMode
  131. {
  132. return _repeatMode;
  133. }
  134. @end