source: trunk/CommonMediaPlayer/Media Players/MPlayer classes/CMPMPPlayerController.m @ 1301

Revision 1301, 6.4 KB checked in by lechium, 4 years ago (diff)

Forgot to check this in a while ago, may need some tweaking but want to add it before any major conflicts arise. added CMPSettings class which isnt used yet, added support for the harmony remote play, pause, ff, rewind buttons

Line 
1/*
2 * CMPMPPlayerController.m
3 * CommonMediaPlayer
4 *
5 * Created by Kevin Bradley on June 5th 2010
6 * Copyright 2010 Common Media Player
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * Lesser General Public License as published by the Free Software Foundation; either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License along with this program; if
18 * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#import "CMPMPPlayerController.h"
23#import "CMPMPPlayer.h"
24#import "CMPATVVersion.h"
25#import "CoreGraphicsServices.h"
26
27
28
29@implementation CMPMPPlayerController
30
31+ (NSSet *)knownPlayers
32{
33        return [NSSet setWithObject:[CMPMPPlayer class]];
34}
35
36#ifdef PLAY_WITH_OVERLAY
37static NSTimer *timer = nil;
38#endif
39
40- (id)initWithScene:(BRRenderScene *)scene player:(id <CMPPlayer>)aPlayer
41{
42        if([[BRMenuController class] instancesRespondToSelector:@selector(initWithScene:)])
43                self = [super initWithScene:scene];
44        else
45                self = [super init];
46        if(!self)
47                return self;
48       
49        [[self list] setDatasource:self];
50       
51        player = [aPlayer retain];
52        [player setController:self];
53       
54        [self setListTitle:@"Initiating MPlayer Playback"];
55        [self setListIcon:nil];
56       
57
58       
59        return self;
60}
61
62
63
64
65
66- (void) dealloc
67{
68
69        [player release];
70        [delegate release];
71        [screenRelease release];
72        [super dealloc];
73}
74
75
76- (id <CMPPlayer>)player
77{
78        return player;
79}
80
81- (void)setPlaybackSettings:(NSDictionary *)settings
82{
83        NSNumber *resume = [settings objectForKey:CMPPlayerResumeTimeKey];
84       
85        if(resume != nil)
86                [player setResumeTime:[resume intValue]];
87
88        BOOL stopValue = TRUE;
89        NSNumber *useStopTimer = [settings objectForKey:CMPPlayerUseStopTimer];
90        if(![useStopTimer boolValue])
91                stopValue = FALSE;
92       
93        [player setUseStopTimer:stopValue];
94       
95        CFBooleanRef passthroughValue = kCFBooleanFalse;
96        NSNumber *passthrough = [settings objectForKey:CMPPlayerUsePassthroughDeviceKey];
97        if([passthrough boolValue])
98        {
99                passthroughValue = kCFBooleanTrue;
100                [player setUsePassthrough:YES];
101        }
102
103       
104        CFStringRef devDomain = CFSTR("com.cod3r.ac3passthroughdevice");
105        CFPreferencesSetAppValue(CFSTR("engageCAC3Device"), passthroughValue, devDomain);
106        CFPreferencesAppSynchronize(devDomain);
107}
108
109- (void)setPlaybackDelegate:(id <CMPPlayerControllerDelegate>)aDelegate
110{
111        delegate = [aDelegate retain];
112}
113
114- (id <CMPPlayerControllerDelegate>)delegate
115{
116        return delegate;
117}
118
119- (void)releaseScreen
120{
121        screenRelease = [[CMPScreenReleaseAction alloc] initWithController:self andSettings:nil];
122        [screenRelease openWithError:nil];
123}
124
125- (void)initiatePlayback
126{
127
128        BOOL resume = NO;
129
130        [self releaseScreen];
131        [player initiatePlaybackWithResume:&resume];
132       
133}
134
135- (void)playbackStopped
136{
137        [[self stack] popController];
138}
139
140- (void)controlWasActivated
141{
142        [super controlWasActivated];
143        //[[BRRenderer singleton] addPlaybackDelegate:self]; -- not sure what this does
144}
145
146
147- (void)wasPushed
148{
149        [super wasPushed];
150        [self performSelector:@selector(initiatePlayback) withObject:nil afterDelay:0.3];
151}
152
153- (void)wasPopped
154{
155        [super wasPopped];
156
157        NSMutableDictionary *endSettings = [[NSMutableDictionary alloc] init];
158        //double elapsed = [player elapsedPlaybackTime];
159        //double duration = [player trackDuration];
160        //NSLog(@"duration: %d, elapsed: %d", elapsed, duration);
161        //if(elapsed >= 0.0)
162        //      [endSettings setObject:[NSNumber numberWithDouble:elapsed] forKey:CMPPlayerResumeTimeKey];
163        //if(duration >= 0.0)
164        //      [endSettings setObject:[NSNumber numberWithDouble:duration] forKey:CMPPlayerDurationTimeKey];
165
166        CFStringRef devDomain = CFSTR("com.cod3r.ac3passthroughdevice");
167        CFPreferencesSetAppValue(CFSTR("engageCAC3Device"), NULL, devDomain);
168        CFPreferencesAppSynchronize(devDomain);
169       
170        [delegate controller:self didEndWithSettings:endSettings];
171        [delegate autorelease];
172        delegate = nil;
173        [endSettings release];
174       
175        [player stopPlayback];
176        [screenRelease closeWithError:nil];
177        //[windowCreation closeWithError:nil];
178}
179
180
181
182
183- (BOOL)brEventAction:(BREvent *)event
184{
185        //NSLog(@"Got event %@", event);
186        BREventRemoteAction action = [CMPATVVersion remoteActionForEvent:event];
187        if(![player playing])
188                return [super brEventAction:event];
189       
190        if([event value] == 0 && action != kBREventRemoteActionMenu)
191                return NO;
192       
193        switch (action) {
194                case kBREventRemoteActionSwipeRight:
195                case kBREventRemoteActionRight:
196                       
197                        [player seekTenForward];
198                       
199                        break;
200                       
201                case kBREventRemoteActionSwipeLeft:
202                case kBREventRemoteActionLeft:
203                       
204                        [player seekTenBack];
205                        break;
206       
207                case kBREventRemoteActionSwipeUp:
208                case kBREventRemoteActionUp:
209                       
210                        [player volumeUp];
211                       
212                        break;
213                case kBREventRemoteActionSwipeDown:
214                case kBREventRemoteActionDown:
215                       
216                        [player volumeDown];
217                        break;
218               
219                case kBREventRemoteActionMenu:
220                       
221                        [player stopPlayback];
222                        break;
223                       
224                case kBREventRemoteActionPlay:
225                case kBREventRemoteActionPlayNew:
226                       
227                        [player play];
228                        break;
229                       
230               
231                case kBREventPlaybackActionSkipAhead:
232                       
233                        if ([player isPlaylist])
234                                [player nextPlaylistItem];
235                        else
236                                [player seekSixtyForward];
237                        break;
238                       
239                case kBREventPlaybackActionSkipBack:
240                        if ([player isPlaylist])
241                                [player nextPlaylistItem];
242                        else
243                                [player seekSixtyBack];
244                        break;
245                       
246                case kBREventPlaybackActionFastForward:
247                       
248                        [player seekSixHundredForward];
249                        break;
250               
251                case kBREventPlaybackActionRewind:
252                       
253                        [player seekSixHundredBackwards];
254                        break;
255                       
256                case kBREventPlaybackActionPlay:
257                       
258                        [player play];
259                        break;
260                       
261                case kBREventPlaybackActionStop:
262                       
263                        [player stopPlayback];
264                        break;
265                       
266                case kBREventPlaybackActionPause:
267                       
268                        [player pause];
269                        break;
270                       
271                default:
272                       
273                        NSLog(@"unknown %d", action);
274                        return [super brEventAction:event];
275        }
276       
277       
278        return YES;
279}
280
281- (NSString *)titleForRow:(long)row {
282        return nil;
283}
284
285-(float)heightForRow:(long)row {
286        return 0.0f;
287}
288
289-(id)itemForRow:(long)row {
290        return nil;
291}
292
293- (long)itemCount {
294        return 0;
295}
296
297- (void)itemSelected:(long)row
298{
299}
300
301- (id<BRMediaPreviewController>)previewControllerForItem:(long)row
302{
303        return nil;
304}
305
306- (id<BRMediaPreviewController>)previewControlForItem:(long)row
307{
308        return [self previewControllerForItem:row];
309}
310
311@end
Note: See TracBrowser for help on using the repository browser.