3 static void *sleepForMe(void)
8 @implementation Controller
12 // atexit((void*)sleepForMe); // Only used for memory leak debugging
14 [NSApp setDelegate:self];
16 // Allocate a VLCVideoView instance and tell it what area to occupy.
17 NSRect rect = NSMakeRect(0, 0, 0, 0);
18 rect.size = [videoHolderView frame].size;
20 videoView = [[VLCVideoView alloc] initWithFrame:rect];
21 [videoHolderView addSubview:videoView];
22 [videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
23 videoView.fillScreen = YES;
25 playlist = [[VLCMediaList alloc] init];
26 [playlist addObserver:self forKeyPath:@"media" options:NSKeyValueObservingOptionNew context:nil];
28 player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
31 [playlistOutline registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
32 [playlistOutline setDoubleAction:@selector(changeAndPlay:)];
35 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
39 - (void)applicationWillTerminate:(NSNotification *)aNotification
41 [playlist removeObserver:self forKeyPath:@"media"];
44 [player setMedia:nil];
50 - (void)changeAndPlay:(id)sender
52 if ([playlistOutline selectedRow] != mediaIndex)
54 [self setMediaIndex:[playlistOutline selectedRow]];
55 if (![player isPlaying])
60 - (void)setMediaIndex:(int)value
62 if ([playlist count] <= 0)
67 if (value > [playlist count] - 1)
68 value = [playlist count] - 1;
71 [player setMedia:[playlist mediaAtIndex:mediaIndex]];
74 - (void)play:(id)sender
76 [self setMediaIndex:mediaIndex+1];
77 if (![player isPlaying])
79 NSLog(@"%@ length = %@", [playlist mediaAtIndex:mediaIndex], [[playlist mediaAtIndex:mediaIndex] lengthWaitUntilDate:[NSDate dateWithTimeIntervalSinceNow:60]]);
84 - (void)pause:(id)sender
86 NSLog(@"Sending pause message to media player...");
90 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
92 if ([keyPath isEqualToString:@"media"] && object == playlist) {
93 [playlistOutline reloadData];
97 // NSTableView Implementation
98 - (int)numberOfRowsInTableView:(NSTableView *)tableView
100 return [playlist count];
103 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
106 return [(VLCMedia *)[playlist mediaAtIndex:row].metaDictionary valueForKey:VLCMetaInformationTitle];
109 - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info
110 proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
112 return NSDragOperationEvery; /* This is for now */
115 - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
116 row:(int)row dropOperation:(NSTableViewDropOperation)operation
119 NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
121 for (i = 0; i < [droppedItems count]; i++)
123 NSString * filename = [droppedItems objectAtIndex:i];
124 VLCMedia * media = [VLCMedia mediaWithURL:[NSURL fileURLWithPath:filename]];
125 [playlist addMedia:media];