VLCMediaListPlayer.m 2.1 KB

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