PDA

View Full Version : QTMovie Load Percent




GRMrGecko
Nov 10, 2009, 12:43 PM
Hello, I'm trying to find out how much the QTMovie has loaded so I can get a Percent of it and draw a progress bar. I know it's possible as QTMovieView's controls shows gray in the middle of how much was loaded.
I've done some looking around and found this hidden method of QTMovie loadedRanges and it's a NSArray with an NSConcreteValue, don't know how to get the value of it, but if I knew, I could probably find the percentage.

Any Help?
Mr. Gecko



Ritsuka
Nov 10, 2009, 01:58 PM
I dunno what loadedRanges does. But I use the following in my app:


@interface QTMovie(IdlingAdditions)
-(QTTime)maxTimeLoaded;
@end


-(double)_percentLoaded
{
NSTimeInterval tMaxLoaded;
NSTimeInterval tDuration;

QTGetTimeInterval([sourceFile duration], &tDuration);
QTGetTimeInterval([sourceFile maxTimeLoaded], &tMaxLoaded);

return (double) tMaxLoaded/tDuration;
}

GRMrGecko
Nov 10, 2009, 06:55 PM
I dunno what loadedRanges does. But I use the following in my app:


@interface QTMovie(IdlingAdditions)
-(QTTime)maxTimeLoaded;
@end


-(double)_percentLoaded
{
NSTimeInterval tMaxLoaded;
NSTimeInterval tDuration;

QTGetTimeInterval([sourceFile duration], &tDuration);
QTGetTimeInterval([sourceFile maxTimeLoaded], &tMaxLoaded);

return (double) tMaxLoaded/tDuration;
}


That may have worked, but it says "Tried to use QTMovie method maxTimeLoaded, which is not allowed when QTMovieOpenForPlaybackAttribute is YES." so now I need to find out how to use loadedRanges. According to FScript, that is what QuickTime uses.

Binding: highlightedTimeRanges
Object bound
<QTMoviePlaybackController>
Key path bound
'selection.loadedRanges'

As you can see there, it gets the movie and gets loadedRanges which is a NSArray containing a NSConcreteValue, don't know how to get the value from NSConcreteValue, but it does says the _value method returns FSGenericPointer which I have no idea how to get the actual value. Any ideas.

kainjow
Nov 10, 2009, 06:59 PM
I think NSConcreteValue is NSValue, so you can use rangeValue to get the NSRange out of it.

Are you loading a movie from a file, or from a URL? QTMovieOpenForPlaybackAttribute enables QuickTime X playback, which I thought was more efficient and so the idea of buffering up a large chunk of the movie wasn't necessary anymore, but I could be wrong. Is this not what you're seeing?

GRMrGecko
Nov 10, 2009, 07:34 PM
I think NSConcreteValue is NSValue, so you can use rangeValue to get the NSRange out of it.

Are you loading a movie from a file, or from a URL? QTMovieOpenForPlaybackAttribute enables QuickTime X playback, which I thought was more efficient and so the idea of buffering up a large chunk of the movie wasn't necessary anymore, but I could be wrong. Is this not what you're seeing?

I'm loading it from a URL and I need QTMovieOpenForPlaybackAttribute for skipping to a part that hasn't been loaded yet. I tried using NSValue rangeValue and it crashed.

kainjow
Nov 10, 2009, 08:41 PM
I'm loading it from a URL and I need QTMovieOpenForPlaybackAttribute for skipping to a part that hasn't been loaded yet. I tried using NSValue rangeValue and it crashed.

Are you sure QTMovieOpenForPlaybackAttribute is required for skipping to a certain part? I saw the email on the mailing list from the QT engineer, and so I doubt there is any other way.

GRMrGecko
Nov 10, 2009, 09:08 PM
Are you sure QTMovieOpenForPlaybackAttribute is required for skipping to a certain part? I saw the email on the mailing list from the QT engineer, and so I doubt there is any other way.

It might not be required but I couldn't find another way. Any ideas on how to get the loadedRanges together? I can make an example so we can run tests together if you want.

GRMrGecko
Nov 11, 2009, 04:31 PM
Ok, this is what I came up with, QuickTime uses loadedRanges to fill the gray bar, there is a notification that gets posted when it's been updated, and that it's most likely not an NSRange, NSPoint, NSRect, or NSSize, so what else could it be?

here is my code so far for testing.
http://mrgeckosmedia.net/LoadedRanges.zip

GRMrGecko
Nov 13, 2009, 12:19 AM
I think I'll just use maxTimeLoaded and then make it an option to have the loading bar or to have the ability to skip through the video, but if someone wants to help me figure this out still, I'm willing to work still. What I found out is what we need to do is make a new struct and add long for start and end, and then get the value of NSValue and apply it to the struct, no idea how to do that, but I think it's pointerValue and then somehow make it return the structs value.

Here is the struct I wrote.
typedef struct _QTRange {
long start;
long end;
} QTRange;

GRMrGecko
Jan 10, 2010, 02:42 AM
Ok, so this is how I do this to make it work with the QTMovieOpenForPlaybackAttribute.

@interface QTMovie (MGMAdditions)
- (NSArray *)loadedRanges;
@end

and then this is how I get the seconds

double loadedtime;
NSArray *timeRanges = [theMovie loadedRanges];
for (int i=0; i<[timeRanges count]; i++) {
loadedtime = (double)[[timeRanges objectAtIndex:i] QTTimeRangeValue].duration.timeValue/[[timeRanges objectAtIndex:i] QTTimeRangeValue].duration.timeScale;
}
And when you do all the calculations for where to place the load bar, you got it working.