VLCMediaListPlayer.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. [_mediaList release];
  34. [super dealloc];
  35. }
  36. - (VLCMediaPlayer *)mediaPlayer
  37. {
  38. return _mediaPlayer;
  39. }
  40. - (void)setMediaList:(VLCMediaList *)mediaList
  41. {
  42. if (_mediaList == mediaList)
  43. return;
  44. [_mediaList release];
  45. _mediaList = [mediaList retain];
  46. libvlc_exception_t ex;
  47. libvlc_exception_init(&ex);
  48. libvlc_media_list_player_set_media_list(instance, [mediaList libVLCMediaList], &ex);
  49. catch_exception(&ex);
  50. [self willChangeValueForKey:@"rootMedia"];
  51. [_rootMedia release];
  52. _rootMedia = nil;
  53. [self didChangeValueForKey:@"rootMedia"];
  54. }
  55. - (VLCMediaList *)mediaList
  56. {
  57. return _mediaList;
  58. }
  59. - (void)setRootMedia:(VLCMedia *)media
  60. {
  61. if (_rootMedia == media)
  62. return;
  63. [_rootMedia release];
  64. _rootMedia = nil;
  65. VLCMediaList *mediaList = [[VLCMediaList alloc] init];
  66. if (media)
  67. [mediaList addMedia:media];
  68. // This will clean rootMedia
  69. [self setMediaList:mediaList];
  70. // Thus set rootMedia here.
  71. _rootMedia = [media retain];
  72. [mediaList release];
  73. }
  74. - (VLCMedia *)rootMedia
  75. {
  76. return _rootMedia;
  77. }
  78. - (void)playMedia:(VLCMedia *)media
  79. {
  80. libvlc_exception_t ex;
  81. libvlc_exception_init(&ex);
  82. libvlc_media_list_player_play_item(instance, [media libVLCMediaDescriptor], &ex);
  83. catch_exception(&ex);
  84. }
  85. - (void)play
  86. {
  87. libvlc_exception_t ex;
  88. libvlc_exception_init(&ex);
  89. libvlc_media_list_player_play(instance, &ex);
  90. catch_exception(&ex);
  91. }
  92. - (void)stop
  93. {
  94. libvlc_exception_t ex;
  95. libvlc_exception_init(&ex);
  96. libvlc_media_list_player_stop(instance, &ex);
  97. catch_exception(&ex);
  98. }
  99. @end