]> git.sesse.net Git - vlc/blob - projects/macosx/frontrow_plugin/VLCPlayerController.m
macosx: FrontRow plugin initial import. Patch by hyei.
[vlc] / projects / macosx / frontrow_plugin / VLCPlayerController.m
1 //
2 //  VLCPlayerController.m
3 //  FRVLC
4 //
5 //  Created by hyei on 06/09/07.
6 //  Copyright 2007 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "VLCPlayerController.h"
10 #import <BackRow/BREvent.h>
11 #import <BackRow/BRLayer.h>
12 #import <BackRow/BRControllerStack.h>
13
14 @implementation VLCPlayerController
15
16 - init
17 {
18     self = [super init];
19     
20     BRLayer * layer = [self layer];
21     _mediaLayer = [VLCMediaLayer layer];
22     _mediaLayer.frame = layer.bounds;
23     _mediaLayer.autoresizingMask = kCALayerWidthSizable|kCALayerHeightSizable;
24     
25     [layer addSublayer:_mediaLayer];
26     
27     return self;
28 }
29
30 - (NSString*)path
31 {
32     return [_mediaLayer.url path];
33 }
34
35 - (void)setPath:(NSString*)path
36 {
37     _mediaLayer.url = [NSURL fileURLWithPath:path];
38 }
39
40 - (void)brEventAction:(BREvent*)event
41 {
42     BREventUsage usage = [event usage];
43     BREventValue value = [event value];
44     VLCMediaPlayer * player = [_mediaLayer player];
45     
46     NSLog(@"usage: %d value: %d", usage, value);
47     
48     switch(usage) {
49         case BREventOKUsage:
50             [_mediaLayer playPause];
51             break;
52         case BREventRightUsage:
53         {
54             NSLog(@"RIGHT");
55             float position = [player position];
56             position += 0.05;
57             position = MIN(1.0, MAX(0.0, position));
58             [player setPosition:position];
59             break;
60         }
61         case BREventLeftUsage:
62         {
63             NSLog(@"LEFT");
64             float position = [player position];
65             position -= 0.05;
66             position = MIN(1.0, MAX(0.0, position));
67             [player setPosition:position];
68             break;
69         }
70         case BREventMenuUsage:
71             [[self stack] popController];
72         default:
73             break;
74     }
75 }
76
77 - (BOOL)firstResponder
78 {
79     return YES;
80 }
81
82 - (void)controlWillDeactivate
83 {
84     [_mediaLayer.player pause];
85     [super controlWillDeactivate];
86 }
87
88 - (void)controlWasActivated
89 {
90     [super controlWasActivated];
91     [_mediaLayer.player play];
92 }
93
94 @end