Added our GPL copyright header to all files
[vlc.git] / projects / macosx / frontrow_plugin / VLCPlayerController.m
1 /*****************************************************************************
2  * VLCPlayerController.m: Front Row plugin
3  *****************************************************************************
4  * Copyright (C) 2007 - 2008 the VideoLAN Team
5  * $Id$
6  *
7  * Authors: hyei
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "VLCPlayerController.h"
25
26 #import <BackRow/BREvent.h>
27 #import <BackRow/BRLayer.h>
28 #import <BackRow/BRControllerStack.h>
29
30 @implementation VLCPlayerController
31
32 - init
33 {
34     self = [super init];
35     
36     BRLayer * layer = [self layer];
37     _mediaLayer = [VLCMediaLayer layer];
38     _mediaLayer.frame = layer.bounds;
39     _mediaLayer.autoresizingMask = kCALayerWidthSizable|kCALayerHeightSizable;
40     
41     [layer addSublayer:_mediaLayer];
42     
43     return self;
44 }
45
46 - (VLCMedia *)media
47 {
48     return [_mediaLayer media];
49 }
50
51 - (void)setMedia:(VLCMedia *)media
52 {
53     _mediaLayer.media = media;
54 }
55
56 - (void)brEventAction:(BREvent*)event
57 {
58     BREventUsage usage = [event usage];
59     BREventValue value = [event value];
60     VLCMediaPlayer * player = [_mediaLayer player];
61     
62     NSLog(@"usage: %d value: %d", usage, value);
63     
64     switch(usage) {
65         case BREventOKUsage:
66             [_mediaLayer playPause];
67             break;
68         case BREventRightUsage:
69         {
70             NSLog(@"RIGHT");
71             float position = [player position];
72             position += 0.05;
73             position = MIN(1.0, MAX(0.0, position));
74             [player setPosition:position];
75             break;
76         }
77         case BREventLeftUsage:
78         {
79             NSLog(@"LEFT");
80             float position = [player position];
81             position -= 0.05;
82             position = MIN(1.0, MAX(0.0, position));
83             [player setPosition:position];
84             break;
85         }
86         case BREventUpUsage:
87         {
88             NSLog(@"UP");
89             [[[VLCLibrary sharedLibrary] audio] setVolume:[[[VLCLibrary sharedLibrary] audio] volume]+20];
90             break;
91         }
92         case BREventDownUsage:
93         {
94             NSLog(@"DOWN");
95             [[[VLCLibrary sharedLibrary] audio] setVolume:[[[VLCLibrary sharedLibrary] audio] volume]-20];
96             break;
97         }
98         case BREventMenuUsage:
99             [[self stack] popController];
100         default:
101             break;
102     }
103 }
104
105 - (BOOL)firstResponder
106 {
107     return YES;
108 }
109
110 - (void)controlWillDeactivate
111 {
112     [_mediaLayer.player pause];
113     [super controlWillDeactivate];
114 }
115
116 - (void)controlWasActivated
117 {
118     [super controlWasActivated];
119     [_mediaLayer.player play];
120 }
121
122 @end