VLCMediaLibrary.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*****************************************************************************
  2. * VLCMediaLibrary.m: VLCKit.framework VLCMediaLibrary implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007, 2014 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. {
  31. void *_mlib;
  32. }
  33. @property (nonatomic) dispatch_once_t once;
  34. @property (nonatomic, readwrite, strong) VLCMediaList * allMedia;
  35. @end
  36. @implementation VLCMediaLibrary
  37. + (VLCMediaLibrary*)sharedMediaLibrary
  38. {
  39. static VLCMediaLibrary * sharedMediaLibrary = nil;
  40. static dispatch_once_t onceToken;
  41. dispatch_once(&onceToken, ^{
  42. sharedMediaLibrary = [[VLCMediaLibrary alloc] init];
  43. });
  44. return sharedMediaLibrary;
  45. }
  46. - (instancetype)init
  47. {
  48. if (self = [super init]) {
  49. _mlib = libvlc_media_library_new( [VLCLibrary sharedInstance]);
  50. libvlc_media_library_load( _mlib );
  51. }
  52. return self;
  53. }
  54. - (void)dealloc
  55. {
  56. libvlc_media_library_release(_mlib);
  57. _mlib = nil; // make sure that the pointer is dead
  58. }
  59. - (VLCMediaList *)allMedia
  60. {
  61. dispatch_once(&_once, ^{
  62. libvlc_media_list_t * p_mlist = libvlc_media_library_media_list( _mlib );
  63. if (p_mlist != NULL)
  64. {
  65. _allMedia = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
  66. libvlc_media_list_release(p_mlist);
  67. }
  68. });
  69. return _allMedia;
  70. }
  71. @end