VLCMediaListPlayer.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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], &ex);
  42. catch_exception(&ex);
  43. }
  44. return self;
  45. }
  46. - (void)dealloc
  47. {
  48. libvlc_media_list_player_release(instance);
  49. [_mediaPlayer release];
  50. [_rootMedia release];
  51. [_mediaList release];
  52. [super dealloc];
  53. }
  54. - (VLCMediaPlayer *)mediaPlayer
  55. {
  56. return _mediaPlayer;
  57. }
  58. - (void)setMediaList:(VLCMediaList *)mediaList
  59. {
  60. if (_mediaList == mediaList)
  61. return;
  62. [_mediaList release];
  63. _mediaList = [mediaList retain];
  64. libvlc_exception_t ex;
  65. libvlc_exception_init(&ex);
  66. libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList], &ex);
  67. catch_exception(&ex);
  68. [self willChangeValueForKey:@"rootMedia"];
  69. [_rootMedia release];
  70. _rootMedia = nil;
  71. [self didChangeValueForKey:@"rootMedia"];
  72. }
  73. - (VLCMediaList *)mediaList
  74. {
  75. return _mediaList;
  76. }
  77. - (void)setRootMedia:(VLCMedia *)media
  78. {
  79. if (_rootMedia == media)
  80. return;
  81. [_rootMedia release];
  82. _rootMedia = nil;
  83. VLCMediaList *mediaList = [[VLCMediaList alloc] init];
  84. if (media)
  85. [mediaList addMedia:media];
  86. // This will clean rootMedia
  87. [self setMediaList:mediaList];
  88. // Thus set rootMedia here.
  89. _rootMedia = [media retain];
  90. [mediaList release];
  91. }
  92. - (VLCMedia *)rootMedia
  93. {
  94. return _rootMedia;
  95. }
  96. - (void)playMedia:(VLCMedia *)media
  97. {
  98. libvlc_exception_t ex;
  99. libvlc_exception_init(&ex);
  100. libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
  101. catch_exception(&ex);
  102. }
  103. - (void)play
  104. {
  105. libvlc_exception_t ex;
  106. libvlc_exception_init(&ex);
  107. libvlc_media_list_player_play(instance, &ex);
  108. catch_exception(&ex);
  109. }
  110. - (void)stop
  111. {
  112. libvlc_exception_t ex;
  113. libvlc_exception_init(&ex);
  114. libvlc_media_list_player_stop(instance, &ex);
  115. catch_exception(&ex);
  116. }
  117. - (void)doNotRepeatAnyItem;
  118. {
  119. libvlc_exception_t ex;
  120. libvlc_exception_init(&ex);
  121. libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_default, &ex);
  122. catch_exception(&ex);
  123. }
  124. - (void)repeatCurrentItem
  125. {
  126. libvlc_exception_t ex;
  127. libvlc_exception_init(&ex);
  128. libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_repeat, &ex);
  129. catch_exception(&ex);
  130. }
  131. - (void)repeatAllItems
  132. {
  133. libvlc_exception_t ex;
  134. libvlc_exception_init(&ex);
  135. libvlc_media_list_player_set_playback_mode(instance, libvlc_playback_mode_loop, &ex);
  136. catch_exception(&ex);
  137. }
  138. @end