VLCMediaLibrary.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*****************************************************************************
  2. * VLCMediaLibrary.m: VLCKit.framework VLCMediaLibrary implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import <Cocoa/Cocoa.h>
  25. #import "VLCMediaLibrary.h"
  26. #import "VLCLibrary.h"
  27. #import "VLCLibVLCBridging.h"
  28. #include <vlc/libvlc.h>
  29. @interface VLCMediaLibrary ()
  30. @property (nonatomic) dispatch_once_t once;
  31. @property (nonatomic, readwrite, strong) VLCMediaList * allMedia;
  32. @end
  33. @implementation VLCMediaLibrary
  34. + (VLCMediaLibrary*)sharedMediaLibrary
  35. {
  36. static VLCMediaLibrary * sharedMediaLibrary = nil;
  37. static dispatch_once_t onceToken;
  38. dispatch_once(&onceToken, ^{
  39. sharedMediaLibrary = [[VLCMediaLibrary alloc] init];
  40. });
  41. return sharedMediaLibrary;
  42. }
  43. - (instancetype)init
  44. {
  45. if (self = [super init]) {
  46. mlib = libvlc_media_library_new( [VLCLibrary sharedInstance]);
  47. libvlc_media_library_load( mlib );
  48. }
  49. return self;
  50. }
  51. - (void)dealloc
  52. {
  53. libvlc_media_library_release(mlib);
  54. mlib = nil; // make sure that the pointer is dead
  55. }
  56. - (VLCMediaList *)allMedia
  57. {
  58. dispatch_once(&_once, ^{
  59. libvlc_media_list_t * p_mlist = libvlc_media_library_media_list( mlib );
  60. _allMedia = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
  61. libvlc_media_list_release(p_mlist);
  62. });
  63. return _allMedia;
  64. }
  65. @end