Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GRMrGecko

macrumors member
Original poster
Jun 7, 2008
89
0
Nowhere and everywhere
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
 
I dunno what loadedRanges does. But I use the following in my app:

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


-(double)_percentLoaded
{
    NSTimeInterval tMaxLoaded;
    NSTimeInterval tDuration;
    
    QTGetTimeInterval([sourceFile duration], &tDuration);
    QTGetTimeInterval([sourceFile maxTimeLoaded], &tMaxLoaded);
    
	return (double) tMaxLoaded/tDuration;
}
 
I dunno what loadedRanges does. But I use the following in my app:

Code:
@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.
 
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 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.
 
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.
 
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.
 
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.
Code:
typedef struct _QTRange {
    long start;
    long end;
} QTRange;
 
Finally figured out.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.