Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMMovieLoadRequest.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (hide annotations) (download)
Sun Nov 22 09:18:18 2009 UTC (14 years, 4 months ago) by masaki
File size: 4976 byte(s)
[Mod] 色々変更。
XspfMMovieLoadRequestとXspfMCheckFileModifiedRequestのイニシャライザを変更。
XSPFMXspfObjectのセッタを変更がなければ何も行わないように修正。
UKKQueueをnotificationではなくdelegeteで使うように変更。無駄なチェックを行わないように微修正。
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    
20 masaki 96 + (id)requestWithObject:(XSPFMXspfObject *)anObject
21 masaki 2 {
22 masaki 96 return [[[self alloc] initWithObject:anObject] autorelease];
23 masaki 2 }
24 masaki 96 - (id)initWithObject:(XSPFMXspfObject *)anObject
25 masaki 2 {
26     self = [super init];
27     self.object = anObject;
28    
29     return self;
30     }
31 masaki 89 - (void)delloc
32     {
33     self.object = nil;
34    
35     [super dealloc];
36     }
37 masaki 95 - (NSTimeInterval)sleepTime
38     {
39     return 1.0;
40     }
41 masaki 2
42     static QTMovie *loadFromMovieURL(NSURL *url)
43     {
44 masaki 88 NSError *error = nil;
45 masaki 2
46 masaki 88 NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
47     url, QTMovieURLAttribute,
48     [NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute,
49     nil];
50     QTMovie *result = [[QTMovie alloc] initWithAttributes:attrs error:&error];
51     if (result == nil) {
52     if (error != nil) {
53     NSLog(@"Couldn't load movie URL, error = %@", error);
54     }
55     }
56 masaki 2
57 masaki 88 return result;
58 masaki 2 }
59    
60     static XspfQTComponent *componentForURL(NSURL *url)
61     {
62     NSError *theErr = nil;
63    
64     NSXMLDocument *d = [[[NSXMLDocument alloc] initWithContentsOfURL:url
65     options:0
66     error:&theErr] autorelease];
67     if(!d) {
68     if(theErr) {
69     NSLog(@"%@", theErr);
70     }
71     return nil;
72     }
73     NSXMLElement *root = [d rootElement];
74     XspfQTComponent *pl = [XspfQTComponent xspfComponemtWithXMLElement:root];
75     if(!pl) {
76     NSLog(@"Can not create XspfQTComponent.");
77     return nil;
78     }
79    
80     return pl;
81     }
82    
83     static inline NSSize maxSizeForFrame(NSSize size, CGSize frame)
84     {
85     NSSize result = size;
86     CGFloat aspectRetio = size.width / size.height;
87     CGFloat frameAspectRetio = frame.width / frame.height;
88    
89     if(aspectRetio > frameAspectRetio) {
90     result.width = frame.width;
91     result.height = result.width / aspectRetio;
92     } else {
93     result.height = frame.height;
94     result.width = result.height * aspectRetio;
95     }
96    
97     return result;
98     }
99    
100     /** ���������������������������������������������������������������������������������������������������������������������������������������������������
101     ** ������������������������������������������������������������
102     ** ���������������������������������������������������������������������
103     ** ������������������������������������������������������������
104     ** ���������������������������������������������������������������������������
105     **/
106     static QTTime calcDefaultThumbnailQTTime(QTMovie *movie)
107     {
108     XspfQTTimeTransformer *t = [[[XspfQTTimeTransformer alloc] init] autorelease];
109    
110     NSValue *pTimeValue = [movie attributeForKey:QTMoviePosterTimeAttribute];
111     id pV = [t transformedValue:pTimeValue];
112     if([pV longValue] == 0) {
113     NSValue *duration = [movie attributeForKey:QTMovieDurationAttribute];
114     id v = [t transformedValue:duration];
115    
116     double newPosterTime = 0;
117     double dDur = [v doubleValue];
118     if(dDur > 15 * 60) {
119     newPosterTime = dDur / 100;
120     } else if(dDur > 60) {
121     newPosterTime = 1;
122     }
123     pTimeValue = [t reverseTransformedValue:[NSNumber numberWithDouble:newPosterTime]];
124     }
125    
126     return [pTimeValue QTTimeValue];
127     }
128     static NSImage *thumbnailForTrackTime(XspfQTComponent *track, NSTimeInterval time, CGSize size)
129     {
130     NSError *theErr = nil;
131     QTMovie *movie = loadFromMovieURL([track movieLocation]);
132    
133     NSValue *sizeValue = [movie attributeForKey:QTMovieNaturalSizeAttribute];
134     NSSize newMaxSize = maxSizeForFrame([sizeValue sizeValue], size);
135    
136     QTTime t;
137     if(time == DBL_MIN) {
138     t = calcDefaultThumbnailQTTime(movie);
139     } else {
140     t = QTMakeTimeWithTimeInterval(time);
141     }
142    
143     NSDictionary *imgProp = [NSDictionary dictionaryWithObjectsAndKeys:
144     QTMovieFrameImageTypeNSImage,QTMovieFrameImageType,
145     [NSValue valueWithSize:newMaxSize], QTMovieFrameImageSize,
146     nil];
147    
148     NSImage *theImage = (NSImage *)[movie frameImageAtTime:t
149     withAttributes:imgProp
150     error:&theErr];
151     if (theImage == nil) {
152     if (theErr != nil) {
153     NSLog(@"Couldn't create CGImageRef, error = %@", theErr);
154     }
155     return NULL;
156     }
157    
158     return theImage;
159     }
160    
161     static NSImage *thumbnailWithComponent(XspfQTComponent *component)
162     {
163     XspfQTComponent *track = [component thumbnailTrack];
164     NSTimeInterval interval = [component thumbnailTimeInterval];
165     CGSize size = { 200, 200 };
166    
167     if(!track) {
168     XspfQTComponent *trackList = [component childAtIndex:0];
169     [trackList setSelectionIndex:0];
170     track = [trackList currentTrack ];
171     }
172    
173     NSImage *thumbnail = thumbnailForTrackTime(track, interval, size);
174    
175     return thumbnail;
176     }
177    
178    
179 masaki 85 - (void)fire
180 masaki 2 {
181 masaki 96 id item = componentForURL(self.object.url);
182 masaki 2 if(!item) return;
183 masaki 7 if([item childrenCount] == 0) return;
184 masaki 2
185 masaki 7 id trackList = [item childAtIndex:0];
186 masaki 71 self.object.movieNum = [NSNumber numberWithInt:[trackList childrenCount]];
187     self.object.thumbnail = thumbnailWithComponent(item);
188 masaki 2 }
189     -(void)terminate
190     {
191     [self doesNotRecognizeSelector:_cmd];
192     }
193     @end

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