39a48111e125dfe87c7b500835f6305d12e6ff38
[vlc.git] / 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
11 #import <BackRow/BREvent.h>
12 #import <BackRow/BRLayer.h>
13 #import <BackRow/BRControllerStack.h>
14
15 @implementation VLCPlayerController
16
17 - init
18 {
19     self = [super init];
20     
21     BRLayer * layer = [self layer];
22     _mediaLayer = [VLCMediaLayer layer];
23     _mediaLayer.frame = layer.bounds;
24     _mediaLayer.autoresizingMask = kCALayerWidthSizable|kCALayerHeightSizable;
25     
26     [layer addSublayer:_mediaLayer];
27     
28     return self;
29 }
30
31 - (VLCMedia *)media
32 {
33     return [_mediaLayer media];
34 }
35
36 - (void)setMedia:(VLCMedia *)media
37 {
38     _mediaLayer.media = media;
39 }
40
41 - (void)brEventAction:(BREvent*)event
42 {
43     BREventUsage usage = [event usage];
44     BREventValue value = [event value];
45     VLCMediaPlayer * player = [_mediaLayer player];
46     
47     NSLog(@"usage: %d value: %d", usage, value);
48     
49     switch(usage) {
50         case BREventOKUsage:
51             [_mediaLayer playPause];
52             break;
53         case BREventRightUsage:
54         {
55             NSLog(@"RIGHT");
56             float position = [player position];
57             position += 0.05;
58             position = MIN(1.0, MAX(0.0, position));
59             [player setPosition:position];
60             break;
61         }
62         case BREventLeftUsage:
63         {
64             NSLog(@"LEFT");
65             float position = [player position];
66             position -= 0.05;
67             position = MIN(1.0, MAX(0.0, position));
68             [player setPosition:position];
69             break;
70         }
71         case BREventUpUsage:
72         {
73             NSLog(@"UP");
74             [[[VLCLibrary sharedLibrary] audio] setVolume:[[[VLCLibrary sharedLibrary] audio] volume]+20];
75             break;
76         }
77         case BREventDownUsage:
78         {
79             NSLog(@"DOWN");
80             [[[VLCLibrary sharedLibrary] audio] setVolume:[[[VLCLibrary sharedLibrary] audio] volume]-20];
81             break;
82         }
83         case BREventMenuUsage:
84             [[self stack] popController];
85         default:
86             break;
87     }
88 }
89
90 - (BOOL)firstResponder
91 {
92     return YES;
93 }
94
95 - (void)controlWillDeactivate
96 {
97     [_mediaLayer.player pause];
98     [super controlWillDeactivate];
99 }
100
101 - (void)controlWasActivated
102 {
103     [super controlWasActivated];
104     [_mediaLayer.player play];
105 }
106
107 @end