VLCMediaDiscoverer.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*****************************************************************************
  2. * VLCMediaDiscoverer.m: VLC.framework VLCMediaDiscoverer implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 the VideoLAN team
  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
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 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 General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import <Cocoa/Cocoa.h>
  25. #import <VLC/VLCMediaDiscoverer.h>
  26. #import "VLCLibrary.h"
  27. #include <vlc/libvlc.h>
  28. @implementation VLCMediaDiscoverer
  29. - (id)initWithName:(NSString *)aServiceName
  30. {
  31. if (self = [super init])
  32. {
  33. libvlc_exception_t ex;
  34. libvlc_exception_init( &ex );
  35. localizedName = nil;
  36. playlist = nil;
  37. mdis = libvlc_media_discoverer_new_from_name( [VLCLibrary sharedInstance],
  38. [aServiceName cString],
  39. &ex );
  40. quit_on_exception( &ex );
  41. }
  42. return self;
  43. }
  44. - (void)dealloc
  45. {
  46. if( localizedName )
  47. [localizedName release];
  48. if( playlist )
  49. [playlist release];
  50. libvlc_media_discoverer_release( mdis );
  51. [super dealloc];
  52. }
  53. - (VLCPlaylist *) playlist
  54. {
  55. if( playlist )
  56. return playlist;
  57. libvlc_media_list_t * p_mlist = libvlc_media_discoverer_media_list( mdis );
  58. VLCPlaylist * ret = [VLCPlaylist playlistWithLibVLCMediaList: p_mlist];
  59. libvlc_media_list_release( p_mlist );
  60. /* Hack until this gets done properly upstream */
  61. char * name = libvlc_media_discoverer_localized_name( mdis );
  62. if( !name )
  63. {
  64. VLCMedia * media = [ret mediaAtIndex: 0];
  65. ret = media ? (VLCPlaylist *)[media subitems] : nil;
  66. }
  67. free(name);
  68. if( ret )
  69. {
  70. playlist = [ret retain];
  71. }
  72. return ret;
  73. }
  74. - (NSString *)localizedName
  75. {
  76. NSString * ret = nil;
  77. char * name = libvlc_media_discoverer_localized_name( mdis );
  78. if( localizedName )
  79. return localizedName;
  80. if (name)
  81. {
  82. ret = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
  83. free( name );
  84. }
  85. /* XXX: Hack until this gets done properly upstream. This is really slow. */
  86. if (!ret)
  87. {
  88. libvlc_media_list_t * p_mlist = libvlc_media_discoverer_media_list( mdis );
  89. ret = [[[[VLCPlaylist playlistWithLibVLCMediaList: p_mlist] mediaAtIndex:0] metaInformation] objectForKey: VLCMetaInformationTitle];
  90. libvlc_media_list_release( p_mlist );
  91. }
  92. if( ret )
  93. {
  94. localizedName = [ret retain];
  95. }
  96. return localizedName;
  97. }
  98. @end