VLCMediaListPlayer.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // VLCMediaListPlayer.m
  3. // VLCKit
  4. //
  5. // Created by Pierre d'Herbemont on 8/24/09.
  6. // Copyright 2009 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "VLCMediaListPlayer.h"
  9. #import "VLCMedia.h"
  10. #import "VLCMediaPlayer.h"
  11. #import "VLCMediaList.h"
  12. #import "VLCLibVLCBridging.h"
  13. @implementation VLCMediaListPlayer
  14. - (id)init
  15. {
  16. if (self = [super init])
  17. {
  18. _mediaPlayer = [[VLCMediaPlayer alloc] init];
  19. libvlc_exception_t ex;
  20. libvlc_exception_init(&ex);
  21. instance = libvlc_media_list_player_new([VLCLibrary sharedInstance], &ex);
  22. catch_exception(&ex);
  23. libvlc_media_list_player_set_media_player(instance, [_mediaPlayer libVLCMediaPlayer], &ex);
  24. catch_exception(&ex);
  25. }
  26. return self;
  27. }
  28. - (void)dealloc
  29. {
  30. libvlc_media_list_player_release(instance);
  31. [_mediaPlayer release];
  32. [_rootMedia release];
  33. [super dealloc];
  34. }
  35. - (VLCMediaPlayer *)mediaPlayer
  36. {
  37. return _mediaPlayer;
  38. }
  39. - (void)setMediaList:(VLCMediaList *)mediaList
  40. {
  41. if (_mediaList == mediaList)
  42. return;
  43. [_mediaList release];
  44. _mediaList = [mediaList retain];
  45. libvlc_exception_t ex;
  46. libvlc_exception_init(&ex);
  47. libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList], &ex);
  48. catch_exception(&ex);
  49. [self willChangeValueForKey:@"rootMedia"];
  50. [_rootMedia release];
  51. _rootMedia = nil;
  52. [self didChangeValueForKey:@"rootMedia"];
  53. }
  54. - (VLCMediaList *)mediaList
  55. {
  56. return _mediaList;
  57. }
  58. - (void)setRootMedia:(VLCMedia *)media
  59. {
  60. if (_rootMedia == media)
  61. return;
  62. [_rootMedia release];
  63. _rootMedia = nil;
  64. VLCMediaList *mediaList = [[VLCMediaList alloc] init];
  65. if (media)
  66. [mediaList addMedia:media];
  67. // This will clean rootMedia
  68. [self setMediaList:mediaList];
  69. // Thus set rootMedia here.
  70. _rootMedia = [media retain];
  71. [mediaList release];
  72. }
  73. - (VLCMedia *)rootMedia
  74. {
  75. return _rootMedia;
  76. }
  77. - (void)playMedia:(VLCMedia *)media
  78. {
  79. libvlc_exception_t ex;
  80. libvlc_exception_init(&ex);
  81. libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
  82. catch_exception(&ex);
  83. }
  84. - (void)play
  85. {
  86. libvlc_exception_t ex;
  87. libvlc_exception_init(&ex);
  88. libvlc_media_list_player_play(instance, &ex);
  89. catch_exception(&ex);
  90. }
  91. - (void)stop
  92. {
  93. libvlc_exception_t ex;
  94. libvlc_exception_init(&ex);
  95. libvlc_media_list_player_stop(instance, &ex);
  96. catch_exception(&ex);
  97. }
  98. @end