]> git.sesse.net Git - vlc/blob - extras/MacOSX/Framework/Examples/test2/Controller.m
MacOSX/Framework: Delete the old test app.
[vlc] / extras / MacOSX / Framework / Examples / test2 / Controller.m
1 #import "Controller.h"
2
3 static void *sleepForMe(void)
4 {
5     while (1) sleep(60);
6 }
7
8 @implementation Controller
9
10 - (void)awakeFromNib
11 {
12 //    atexit((void*)sleepForMe);    // Only used for memory leak debugging
13
14     [NSApp setDelegate:self];
15
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;
19     
20     videoView = [[VLCVideoView alloc] initWithFrame:rect];
21     [videoHolderView addSubview:videoView];
22     [videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
23
24     playlist = [[VLCMediaList alloc] init];
25     [playlist setDelegate:self];
26     
27     player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
28     mediaIndex = -1;
29
30     [playlistOutline registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
31     [playlistOutline setDoubleAction:@selector(changeAndPlay:)];
32 }
33
34 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
35 {
36 }
37
38 - (void)applicationWillTerminate:(NSNotification *)aNotification
39 {
40     [player pause];
41     [player setMedia:nil];
42     [player release];
43     [playlist release];
44     [videoView release];
45 }
46
47
48 - (void)changeAndPlay:(id)sender
49 {
50     if ([playlistOutline selectedRow] != mediaIndex)
51     {
52                 [self setMediaIndex:[playlistOutline selectedRow]];
53                 if (![player isPlaying])
54                         [player play];
55     }
56 }
57
58 - (void)setMediaIndex:(int)value
59 {
60     if ([playlist count] <= 0)
61                 return;
62     
63     if (value < 0)
64                 value = 0;
65     if (value > [playlist count] - 1)
66                 value = [playlist count] - 1;
67     
68     mediaIndex = value;
69     [player setMedia:[playlist mediaAtIndex:mediaIndex]];
70 }
71
72 - (void)play:(id)sender
73 {
74     [self setMediaIndex:mediaIndex+1];
75     if (![player isPlaying])
76                 [player play];
77 }
78
79 - (void)pause:(id)sender
80 {
81     NSLog(@"Sending pause message to media player...");
82     [player pause];
83 }
84
85 //
86 - (void)mediaList:(VLCMediaList *)mediaList mediaAdded:(VLCMedia *)media atIndex:(int)index
87 {
88     [playlistOutline reloadData];
89 }
90
91 - (void)mediaList:(VLCMediaList *)mediaList mediaRemoved:(VLCMedia *)media atIndex:(int)index
92 {
93     [playlistOutline reloadData];
94 }
95
96 // NSTableView Implementation
97 - (int)numberOfRowsInTableView:(NSTableView *)tableView
98 {
99     return [playlist count];
100 }
101
102 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
103                         row:(int)row
104 {
105     return [[playlist mediaAtIndex:row] description];
106 }
107
108 - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info 
109                                  proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
110 {
111     return NSDragOperationEvery; /* This is for now */
112 }
113
114 - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
115                           row:(int)row dropOperation:(NSTableViewDropOperation)operation
116 {
117     int i;
118     NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
119     
120     for (i = 0; i < [droppedItems count]; i++)
121     {
122         NSString * filename = [droppedItems objectAtIndex:i];
123                 VLCMedia * media = [VLCMedia mediaWithURL:[NSURL fileURLWithPath:filename]];
124                 NSLog(@"%@ length = %@", media, [media lengthWaitUntilDate:[NSDate dateWithTimeIntervalSinceNow:60]]);
125                 [playlist addMedia:media];
126     }
127     return YES;
128 }    
129
130 @end