source: branches/PlayerFramework/CommonMediaPlayer/Classes/CMPPlayerManager.m @ 1153

Revision 1153, 5.9 KB checked in by lechium, 5 years ago (diff)

feed preferences into the dvdplayercontroller

RevLine 
[1095]1/*
2 * CMPPlayerManager.m
3 * CommonMediaPlayer
4 *
5 * Created by Graham Booker on Feb. 1 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 "CMPPlayerManager.h"
23#import "CMPBaseMediaAsset.h"
24#import "CMPDVDPlayer.h"
25#import "CMPDVDPlayerController.h"
26#import "CMPLeopardDVDPlayer.h"
27#import "CMPLeopardDVDPlayerController.h"
[1103]28#import "CMPISODVDPlayer.h"
[1136]29#import "CMPDVDImporter.h"
30
[1095]31@implementation CMPPlayerManager
32
33+ (CMPPlayerManager *)sharedPlayerManager
34{
35        CMPPlayerManager *shared = nil;
36        if(shared == nil)
37                shared = [[CMPPlayerManager alloc] init];
38       
39        return shared;
40}
41
[1148]42+ (int)version
43{
44        return CMPVersion;
45}
46
[1095]47- (id) init
48{
49        self = [super init];
50        if (self == nil)
51                return self;
52       
53        knownPlayers = [[NSMutableSet alloc] init];
54        knownControllers = [[NSMutableSet alloc] init];
55        playersForTypes = [[NSMutableDictionary alloc] init];
56       
[1107]57//      [self registerPlayer:[CMPLeopardDVDPlayer class] forType:CMPPlayerManagerFileTypeVideo_TS withExtensions:[NSArray arrayWithObject:@""]];
58//      [knownControllers addObject:[CMPLeopardDVDPlayerController class]];
59
60        [self registerPlayer:[CMPDVDPlayer class] forType:CMPPlayerManagerFileTypeVideo_TS withExtensions:[NSArray arrayWithObject:@""]];
[1095]61        [knownControllers addObject:[CMPDVDPlayerController class]];
[1107]62
[1116]63        [self registerPlayer:[CMPISODVDPlayer class] forType:CMPPlayerManagerFileTypeDVDImage withExtensions:[NSArray arrayWithObjects:@"iso", @"dmg", @"img", nil]];
[1095]64       
[1136]65        [self registerPlayer:[CMPDVDImporter class] forType:CMPPlayerManagerFileTypeDVDImport withExtensions:[NSArray arrayWithObject:@""]];
66       
[1095]67        return self;
68}
69
70- (void) dealloc
71{
72        [knownPlayers release];
73        [knownControllers release];
74        [playersForTypes release];
75        [super dealloc];
76}
77
78- (void)registerPlayer:(Class)player forTypes:(NSDictionary *)types
79{
[1107]80        NSEnumerator *typeEnum = [types keyEnumerator];
81        NSNumber *typeKey;
82        while((typeKey = [typeEnum nextObject]) != nil)
83        {
84                [self registerPlayer:player forType:[typeKey intValue] withExtensions:[types objectForKey:typeKey]];
85        }
86}
87
88- (void)registerPlayer:(Class)player forType:(CMPPlayerManagerFileType)type withExtensions:(NSArray *)extensions
89{
90        NSNumber *typeKey = [NSNumber numberWithInt:type];
91        NSMutableDictionary *typeDict = [playersForTypes objectForKey:typeKey];
92        if(typeDict == nil)
93        {
94                typeDict = [[NSMutableDictionary alloc] init];
95                [playersForTypes setObject:typeDict forKey:typeKey];
96                [typeDict release];
97        }
[1095]98       
[1107]99        NSEnumerator *extensionEnum = [extensions objectEnumerator];
100        NSString *extension;
101        while((extension = [extensionEnum nextObject]) != nil)
102        {
103                NSMutableArray *players = [typeDict objectForKey:extension];
104                if(players == nil)
105                {
106                        players = [[NSMutableArray alloc] init];
107                        [typeDict setObject:players forKey:extension];
108                        [players release];
109                }
110                if(![players containsObject:player])
111                        [players addObject:player];
112        }
113        if(![knownPlayers containsObject:player])
114                [knownPlayers addObject:player];
[1095]115}
116
117- (id <CMPPlayer>)playerForPath:(NSString *)path type:(CMPPlayerManagerFileType)type preferences:(NSDictionary *)preferences
118{
119        NSString *ext = [path pathExtension];
120        NSMutableArray *players = [[NSMutableArray alloc] init];
121       
122        NSDictionary *playersForExtension = [playersForTypes objectForKey:[NSNumber numberWithInt:type]];
123        if([ext length])
124        {
[1103]125                NSArray *specificPlayers = [playersForExtension objectForKey:[ext lowercaseString]];
[1095]126                if([specificPlayers count])
127                        [players addObjectsFromArray:specificPlayers];
128        }
129        NSArray *genericPlayers = [playersForExtension objectForKey:@""];
130        if([genericPlayers count])
131                [players addObjectsFromArray:genericPlayers];
132
133        NSLog(@"List of players is %@", players);
134        NSEnumerator *playerEnum = [players objectEnumerator];
135        Class playerClass;
136        id <CMPPlayer> player = nil;
137        while((playerClass = [playerEnum nextObject]) != nil)
138        {
139                player = [[playerClass alloc] init];
140               
141                NSLog(@"Testing %@", player);
142                BOOL canPlay = [player canPlay:path withError:nil];
143                NSLog(@"can play is %d", canPlay);
144                if(canPlay)
145                {
146                        CMPBaseMediaAsset *asset = [[CMPBaseMediaAsset alloc] initWithMediaURL:[NSURL fileURLWithPath:path]];
147                        canPlay &= [player setMedia:asset error:nil];
148                        NSLog(@"Set asset is %d", canPlay);
149                        [asset release];
150                }
151                if(canPlay)
152                {
153                        NSLog(@"Using Player");
154                        [player retain];
155                        break;
156                }
157               
158                [player release];
159                player = nil;
160        }
161       
162        [players release];
163       
164        return [player autorelease];
165}
166
167- (id <CMPPlayerController>)playerControllerForPlayer:(id <CMPPlayer>)player scene:(BRRenderScene *)scene preferences:(NSDictionary *)preferences
168{
169        NSMutableSet *goodControllers = [[NSMutableSet alloc] init];
170        NSSet *playersControllers = [[player class] knownControllers];
171        if([playersControllers count])
172                [goodControllers unionSet:playersControllers];
173       
174        NSEnumerator *controllerEnum = [knownControllers objectEnumerator];
175        Class <CMPPlayerController> controllerClass;
176        while((controllerClass = [controllerEnum nextObject]) != nil)
177        {
178                if([[controllerClass knownPlayers] containsObject:[player class]])
179                        [goodControllers addObject:controllerClass];
180        }
181       
182        NSLog(@"Controllers is %@", goodControllers);
183       
184        //XXX Prefs
185        id <CMPPlayerController> controller = [[(Class)[goodControllers anyObject] alloc] initWithScene:scene player:player];
[1153]186        [controller setPlaybackSettings:preferences];
[1095]187        return [controller autorelease];
188}
189
190@end
Note: See TracBrowser for help on using the repository browser.