VLCMediaListPlayer.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 VLC authors and VideoLAN
  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 it
  13. * under the terms of the GNU Lesser General Public License as published by
  14. * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * along with this program; if not, write to the Free Software Foundation,
  24. * 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. instance = libvlc_media_list_player_new([VLCLibrary sharedInstance]);
  38. libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer]);
  39. }
  40. return self;
  41. }
  42. - (void)dealloc
  43. {
  44. libvlc_media_list_player_release(instance);
  45. [_mediaPlayer release];
  46. [_rootMedia release];
  47. [_mediaList release];
  48. [super dealloc];
  49. }
  50. - (VLCMediaPlayer *)mediaPlayer
  51. {
  52. return _mediaPlayer;
  53. }
  54. - (void)setMediaList:(VLCMediaList *)mediaList
  55. {
  56. if (_mediaList == mediaList)
  57. return;
  58. [_mediaList release];
  59. _mediaList = [mediaList retain];
  60. libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList]);
  61. [self willChangeValueForKey:@"rootMedia"];
  62. [_rootMedia release];
  63. _rootMedia = nil;
  64. [self didChangeValueForKey:@"rootMedia"];
  65. }
  66. - (VLCMediaList *)mediaList
  67. {
  68. return _mediaList;
  69. }
  70. - (void)setRootMedia:(VLCMedia *)media
  71. {
  72. if (_rootMedia == media)
  73. return;
  74. [_rootMedia release];
  75. _rootMedia = nil;
  76. VLCMediaList *mediaList = [[VLCMediaList alloc] init];
  77. if (media)
  78. [mediaList addMedia:media];
  79. // This will clean rootMedia
  80. [self setMediaList:mediaList];
  81. // Thus set rootMedia here.
  82. _rootMedia = [media retain];
  83. [mediaList release];
  84. }
  85. - (VLCMedia *)rootMedia
  86. {
  87. return _rootMedia;
  88. }
  89. - (void)playMedia:(VLCMedia *)media
  90. {
  91. libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor]);
  92. }
  93. - (void)play
  94. {
  95. libvlc_media_list_player_play(instance);
  96. }
  97. - (void)stop
  98. {
  99. libvlc_media_list_player_stop(instance);
  100. }
  101. - (void)setRepeatMode:(VLCRepeatMode)repeatMode
  102. {
  103. libvlc_playback_mode_t mode;
  104. switch (repeatMode) {
  105. case VLCRepeatAllItems:
  106. mode = libvlc_playback_mode_loop;
  107. break;
  108. case VLCDoNotRepeat:
  109. mode = libvlc_playback_mode_default;
  110. break;
  111. case VLCRepeatCurrentItem:
  112. mode = libvlc_playback_mode_repeat;
  113. break;
  114. default:
  115. NSAssert(0, @"Should not be reached");
  116. break;
  117. }
  118. libvlc_media_list_player_set_playback_mode(instance, mode);
  119. _repeatMode = repeatMode;
  120. }
  121. - (VLCRepeatMode)repeatMode
  122. {
  123. return _repeatMode;
  124. }
  125. @end