Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMMovieLoadRequest.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 88 - (hide annotations) (download)
Thu Nov 19 14:48:44 2009 UTC (14 years, 5 months ago) by masaki
File size: 4950 byte(s)
[Refactoring] 不要になったクラスとその使用を削除。
1 masaki 2 //
2     // XspfMMovieLoadRequest.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/01.
6     // Copyright 2009 masakih. All rights reserved.
7     //
8    
9     #import "XspfMMovieLoadRequest.h"
10    
11     #import <QTKit/QTKit.h>
12     #import "XspfQTComponent.h"
13     #import "XspfQTValueTransformers.h"
14    
15    
16     @implementation XspfMMovieLoadRequest
17    
18     @synthesize object;
19     @synthesize url;
20    
21 masaki 71 + (id)requestWithObject:(XSPFMXspfObject *)anObject url:(NSURL *)anUrl;
22 masaki 2 {
23     return [[[self alloc] initWithObject:anObject url:anUrl] autorelease];
24     }
25 masaki 71 - (id)initWithObject:(XSPFMXspfObject *)anObject url:(NSURL *)anUrl
26 masaki 2 {
27     self = [super init];
28     self.object = anObject;
29     self.url = anUrl;
30    
31     return self;
32     }
33    
34     static QTMovie *loadFromMovieURL(NSURL *url)
35     {
36 masaki 88 NSError *error = nil;
37 masaki 2
38 masaki 88 NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
39     url, QTMovieURLAttribute,
40     [NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute,
41     nil];
42     QTMovie *result = [[QTMovie alloc] initWithAttributes:attrs error:&error];
43     if (result == nil) {
44     if (error != nil) {
45     NSLog(@"Couldn't load movie URL, error = %@", error);
46     }
47     }
48 masaki 2
49 masaki 88 return result;
50 masaki 2 }
51    
52     static XspfQTComponent *componentForURL(NSURL *url)
53     {
54     NSError *theErr = nil;
55    
56     NSXMLDocument *d = [[[NSXMLDocument alloc] initWithContentsOfURL:url
57     options:0
58     error:&theErr] autorelease];
59     if(!d) {
60     if(theErr) {
61     NSLog(@"%@", theErr);
62     }
63     return nil;
64     }
65     NSXMLElement *root = [d rootElement];
66     XspfQTComponent *pl = [XspfQTComponent xspfComponemtWithXMLElement:root];
67     if(!pl) {
68     NSLog(@"Can not create XspfQTComponent.");
69     return nil;
70     }
71    
72     return pl;
73     }
74    
75     static inline NSSize maxSizeForFrame(NSSize size, CGSize frame)
76     {
77     NSSize result = size;
78     CGFloat aspectRetio = size.width / size.height;
79     CGFloat frameAspectRetio = frame.width / frame.height;
80    
81     if(aspectRetio > frameAspectRetio) {
82     result.width = frame.width;
83     result.height = result.width / aspectRetio;
84     } else {
85     result.height = frame.height;
86     result.width = result.height * aspectRetio;
87     }
88    
89     return result;
90     }
91    
92     /** ���������������������������������������������������������������������������������������������������������������������������������������������������
93     ** ������������������������������������������������������������
94     ** ���������������������������������������������������������������������
95     ** ������������������������������������������������������������
96     ** ���������������������������������������������������������������������������
97     **/
98     static QTTime calcDefaultThumbnailQTTime(QTMovie *movie)
99     {
100     XspfQTTimeTransformer *t = [[[XspfQTTimeTransformer alloc] init] autorelease];
101    
102     NSValue *pTimeValue = [movie attributeForKey:QTMoviePosterTimeAttribute];
103     id pV = [t transformedValue:pTimeValue];
104     if([pV longValue] == 0) {
105     NSValue *duration = [movie attributeForKey:QTMovieDurationAttribute];
106     id v = [t transformedValue:duration];
107    
108     double newPosterTime = 0;
109     double dDur = [v doubleValue];
110     if(dDur > 15 * 60) {
111     newPosterTime = dDur / 100;
112     } else if(dDur > 60) {
113     newPosterTime = 1;
114     }
115     pTimeValue = [t reverseTransformedValue:[NSNumber numberWithDouble:newPosterTime]];
116     }
117    
118     return [pTimeValue QTTimeValue];
119     }
120     static NSImage *thumbnailForTrackTime(XspfQTComponent *track, NSTimeInterval time, CGSize size)
121     {
122     NSError *theErr = nil;
123     QTMovie *movie = loadFromMovieURL([track movieLocation]);
124    
125     NSValue *sizeValue = [movie attributeForKey:QTMovieNaturalSizeAttribute];
126     NSSize newMaxSize = maxSizeForFrame([sizeValue sizeValue], size);
127    
128     QTTime t;
129     if(time == DBL_MIN) {
130     t = calcDefaultThumbnailQTTime(movie);
131     } else {
132     t = QTMakeTimeWithTimeInterval(time);
133     }
134    
135     NSDictionary *imgProp = [NSDictionary dictionaryWithObjectsAndKeys:
136     QTMovieFrameImageTypeNSImage,QTMovieFrameImageType,
137     [NSValue valueWithSize:newMaxSize], QTMovieFrameImageSize,
138     nil];
139    
140     NSImage *theImage = (NSImage *)[movie frameImageAtTime:t
141     withAttributes:imgProp
142     error:&theErr];
143     if (theImage == nil) {
144     if (theErr != nil) {
145     NSLog(@"Couldn't create CGImageRef, error = %@", theErr);
146     }
147     return NULL;
148     }
149    
150     return theImage;
151     }
152    
153     static NSImage *thumbnailWithComponent(XspfQTComponent *component)
154     {
155     XspfQTComponent *track = [component thumbnailTrack];
156     NSTimeInterval interval = [component thumbnailTimeInterval];
157     CGSize size = { 200, 200 };
158    
159     if(!track) {
160     XspfQTComponent *trackList = [component childAtIndex:0];
161     [trackList setSelectionIndex:0];
162     track = [trackList currentTrack ];
163     }
164    
165     NSImage *thumbnail = thumbnailForTrackTime(track, interval, size);
166    
167     return thumbnail;
168     }
169    
170    
171 masaki 85 - (void)fire
172 masaki 2 {
173     id item = componentForURL(self.url);
174     if(!item) return;
175 masaki 7 if([item childrenCount] == 0) return;
176 masaki 2
177 masaki 7 id trackList = [item childAtIndex:0];
178 masaki 71 self.object.movieNum = [NSNumber numberWithInt:[trackList childrenCount]];
179     self.object.thumbnail = thumbnailWithComponent(item);
180 masaki 2 }
181     -(void)terminate
182     {
183     [self doesNotRecognizeSelector:_cmd];
184     }
185     @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26