Controller.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #import "Controller.h"
  2. static void *sleepForMe(void)
  3. {
  4. while (1) sleep(60);
  5. }
  6. @implementation Controller
  7. - (void)awakeFromNib
  8. {
  9. // atexit((void*)sleepForMe); // Only used for memory leak debugging
  10. [NSApp setDelegate:self];
  11. // Allocate a VLCVideoView instance and tell it what area to occupy.
  12. NSRect rect = NSMakeRect(0, 0, 0, 0);
  13. rect.size = [videoHolderView frame].size;
  14. videoView = [[VLCVideoView alloc] initWithFrame:rect];
  15. [videoHolderView addSubview:videoView];
  16. [videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
  17. playlist = [[VLCMediaList alloc] init];
  18. [playlist setDelegate:self];
  19. player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
  20. mediaIndex = -1;
  21. [playlistOutline registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
  22. [playlistOutline setDoubleAction:@selector(changeAndPlay:)];
  23. }
  24. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  25. {
  26. }
  27. - (void)applicationWillTerminate:(NSNotification *)aNotification
  28. {
  29. [player pause];
  30. [player setMedia:nil];
  31. [player release];
  32. [playlist release];
  33. [videoView release];
  34. }
  35. - (void)changeAndPlay:(id)sender
  36. {
  37. if ([playlistOutline selectedRow] != mediaIndex)
  38. {
  39. [self setMediaIndex:[playlistOutline selectedRow]];
  40. if (![player isPlaying])
  41. [player play];
  42. }
  43. }
  44. - (void)setMediaIndex:(int)value
  45. {
  46. if ([playlist count] <= 0)
  47. return;
  48. if (value < 0)
  49. value = 0;
  50. if (value > [playlist count] - 1)
  51. value = [playlist count] - 1;
  52. mediaIndex = value;
  53. [player setMedia:[playlist mediaAtIndex:mediaIndex]];
  54. }
  55. - (void)play:(id)sender
  56. {
  57. [self setMediaIndex:mediaIndex+1];
  58. if (![player isPlaying])
  59. [player play];
  60. }
  61. - (void)pause:(id)sender
  62. {
  63. NSLog(@"Sending pause message to media player...");
  64. [player pause];
  65. }
  66. //
  67. - (void)mediaList:(VLCMediaList *)mediaList mediaAdded:(VLCMedia *)media atIndex:(int)index
  68. {
  69. [playlistOutline reloadData];
  70. }
  71. - (void)mediaList:(VLCMediaList *)mediaList mediaRemoved:(VLCMedia *)media atIndex:(int)index
  72. {
  73. [playlistOutline reloadData];
  74. }
  75. // NSTableView Implementation
  76. - (int)numberOfRowsInTableView:(NSTableView *)tableView
  77. {
  78. return [playlist count];
  79. }
  80. - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
  81. row:(int)row
  82. {
  83. return [[playlist mediaAtIndex:row] description];
  84. }
  85. - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info
  86. proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
  87. {
  88. return NSDragOperationEvery; /* This is for now */
  89. }
  90. - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
  91. row:(int)row dropOperation:(NSTableViewDropOperation)operation
  92. {
  93. int i;
  94. NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
  95. for (i = 0; i < [droppedItems count]; i++)
  96. {
  97. NSString * filename = [droppedItems objectAtIndex:i];
  98. VLCMedia * media = [VLCMedia mediaWithURL:[NSURL fileURLWithPath:filename]];
  99. NSLog(@"%@ length = %@", media, [media lengthWaitUntilDate:[NSDate dateWithTimeIntervalSinceNow:60]]);
  100. [playlist addMedia:media];
  101. }
  102. return YES;
  103. }
  104. @end