- (QTTime)QTTimeValue, currenttime of a movie syntax issues!

Hi All

QTTime currentPlayTime = [[mMovie attributeForKey:QTMovieCurrentTimeAttribute] QTTimeValue];
		                                        [mTimeDisplay setStringValue:QTStringFromTime(currentPlayTime)];

I understand the the above code and can get it to work if i import the .m & .h files from an existing example. The problem is that don’t need the other 1000 lines of code in the files.
I have tried my utmost to convert to ASOBJC. When i log the current time , I get a weird value that i can’t replicate as i have screwed all my code up! The value is some sort of array that has something like the following in it “kisd <0000000000hj> ssid blah blah”

I have created the movie object with QTMovieOpenForPlaybackAttribute and i can control it, change aspect ratio, get it to loop etc, but what seems to be the easiest function of getting the currentTime has stumped me!

Here are some of the crazy ways i have tried

QTTime’s valueWithQTTime(theMovie’s currentTime)
theMovie’s attributeForKey_QTMovieCurrentTimeAttribute_()
theMovie’s QTStringFromTime(currentTime)
theMovie’s QTTime’s valueWithQTTime(theMovie’s currentTime)
current application’s theMovieView’s theMovie’s currentTime()
set thetime to QTTime’s currentTime(theMovie)
current application’s class “QTTime”'s currentTime()

( to name a few)

Please can someone point me in the right direction

Regards

Paul

You could try either:

set currentPlayTime to theMovie's attributeForKey_("QTMovieCurrentTimeAttribute")'s QTTimeValue()
set theString to current application's QTStringFromTime(currentPlayTime)

or:

set currentPlayTime to theMovie's attributeForKey_(current application's QTMovieCurrentTimeAttribute)'s QTTimeValue()
set theString to current application's QTStringFromTime(currentPlayTime)

The problem is that QTStringFromTime is a function, not a method, and it may not work.

But what’s your objection to the Objective-C code? Can’t you trim it? And if not, does it matter?

Thank you once again, I will give it a bash. The objective c is working well, i think a trimming session may well be on the cards!

Regards

Paul

I had this same question a couple of months ago, and got the same error I’m getting wtih your sample.

“can’t bridge argument of type {?=qqq}.” There appear to be some things that ASOC can’t do.

My objection is my inability to understand it (yet)…and if you or Pezwell can trim it and give a quick example how I can use it in my app, I’d be greatly appreciative. I’ve “worked around” the issue by ignoring it . It’s not necessary for my app, but would be very very useful! :slight_smile:

That’s right. It can only deal in objects, such as NSNumbers and NSStrings. It can also deal in ints, floats, NSRanges, and a couple of other non-object types by converting them to objects, but any other non-object types are off-limits. QTTime is a struct, not an object type.

  1. Add the QTKit.framework to your project.

Something like this:

  1. Add a new Objective-C class to your project (New → File), and call it something like CallQTStuff.

  2. Edit the .h file to this:

#import <Foundation/Foundation.h>

@interface CallQTStuff : NSObject

-(NSString *)currentTimeFromMovie:(QTMovie *)movie;

@end

  1. Edit the .m file to this:
#import "CallQTStuff.h"
#import <QTKit/QTKit.h>

@implementation CallQTStuff

-(NSString *)currentTimeFromMovie:(QTMovie *)movie {
    QTTime currentPlayTime = [[movie attributeForKey:QTMovieCurrentTimeAttribute] QTTimeValue];
    return QTStringFromTime(currentPlayTime);
}

@end

  1. Add a new NSObject blue cube to your .xib, and change its class to CallQTStuff.

  2. Add a property to your script, set its value to missing value, and in the interface connect it to the blue cube representing CallQTStuff. Let’s say it’s called myQTCollection.

  3. When you want to get the time, call it like this:

set theString to myQTCollection's currentTimeFromMovie_(theMovie) 

Thank you so much - Worked perfectly for my purpose! As always, I really appreciate your posts here and have found your book and it’s examples indispensable. Without your help, my app wouldn’t do 1/10th what it does :slight_smile:

Thanks again,

Scott

A lot much more elegant solution !

Mine was pretty similar but i had a problem getting the values passed back to my ASOBJC script which is what i needed.

But what I did get to work using purely ASOBJC was the following, but I could not get the value into a usable
value:

set curTime to (theMovie's movieAttributes()'s QTMovieCurrentTimeAttribute's QTTimeValue) 
log curTime

which gave me the following result

<00000000 00000000 01000000 00000000 00000000 00000000>

<5f8eb755 02000000 00ca9a3b 00000000 00000000 00000000>

The first value was at 0 seconds, the second was at about 10 seconds.

I am assuming that the are values that are in the QTTime format, but no matter what I did, I also got the bridge error {?=qqq}

I am going to give a Shane’s new methods a bash as I need to do time calculations in ASOBJC. Will post any new discoveries if they happen.

Thanks again for everyones input as there has not been too much info on the topic!!

Regards

Pez

curTime is a C structure containing two members: the elapsed time and the frame rate.
To coerce it to something readable the function QTStringFromTime() is needed

I am happy to email you my project if you would like to have a look at it. It is a little messy as it is a test project and
it is filled with lots of code examples that work ( but placed in the incorrect places - i am a bit of lazy programmer)

Essentially I have been getting certain code to work then transferring it to a proper project. But as it stands the test project has the following working code.

-Fade a movie in and out while playing.
-Plays full screen ( cmd + F ) - 10.6 code - not the new 10.7 fullscreen options
-Show or hide the movie controller
-Toggle Movie Aspect ratio
-Uses timers to display current time and duration of movies
-Sets the window background to black
-Pause and play
-Go back to the beginning of a movie
-Auto loads a specific movie at startup ( you would need to change the path to a movie on your system)
-etc

There are no interface buttons and all the code is linked to key presses.

Kind Regards

Paul

curTime according to what i can see is just a variable name that was used in the code. But then again, I could be mistaken.

I was wrong, the QTTime structure has 3 members

From the documentation

[i]QTTimeValue
Returns a QTTime structure that contains the time in an NSValue object.

  • (QTTime)QTTimeValue[/i]

QTTime
Defines the value and time scale of a time.
typedef struct { long long timeValue; long timeScale; long flags; }

Hi Stefan

As it stands I am able to get the duration of a movie and the current time ( both as string). What I am bring to achieve at the moment is to get a time comparison of the current time and the duration to check if the movie is about to end so i can cross fade between the next movie.

Basically in natural language I want to say:

If movie’s ( duration - current time) => movie’s ( duration - 1 second ) then
do cross fades
end if

I can go the long way and change the strings back to numbers but I want to try implement QTKIT_EXTERN NSComparisonResult QTTimeCompare (QTTime time, QTTime otherTime) as per the documentation.
As it stands i have used Shane’s above code and get a current time string and a duration string using the following

.H file

#import <Foundation/Foundation.h>

@interface CallQTStuff : NSObject

-(NSString *)currentTimeFromMovie:(QTMovie *)movie;
-(NSString *)movieDuration:(QTMovie *)movie;
 
@end

.M File

@implementation CallQTStuff

-(NSString *)currentTimeFromMovie:(QTMovie *)movie {
	QTTime currentPlayTime = [[movie attributeForKey:QTMovieCurrentTimeAttribute] QTTimeValue];
		//return currentPlayTime;
		 return QTStringFromTime(currentPlayTime);
}

-(NSString *)movieDuration:(QTMovie *)movie {
	QTTime currentDuration = [[movie attributeForKey:QTMovieDurationAttribute] QTTimeValue];
	return QTStringFromTime(currentDuration);
}
 
@end

I want to add a third option using the QTKIT_EXTERN NSComparisonResult QTTimeCompare (QTTime time, QTTime otherTime) but I have no idea how to translate the documentation into the .m and . h file in the required structure.
Any pointers will be HUGLEY appreciated

Kind Regards

Pez

QTTimeCompare will just tell you if the first time is bigger than, equal to, or smaller than the second, which is not what you want. QTTimeDecrement is probably the answer, something like this:

-(NSString *)timeLeftToPlay:(QTMovie *)movie {
   QTTime currentPlayTime = [[movie attributeForKey:QTMovieCurrentTimeAttribute] QTTimeValue];
   QTTime duration = [[movie attributeForKey:QTMovieDurationAttribute] QTTimeValue];
   QTTime theDiff = QTTimeDecrement(duration, currentPlayTime)
        return QTStringFromTime(theDiff);
}

Actually, you probably want the value in seconds, so try (untested):

-(NSNumber *)secondsLeftToPlay:(QTMovie *)movie {
QTTime currentPlayTime = [[movie attributeForKey:QTMovieCurrentTimeAttribute] QTTimeValue];
QTTime duration = [[movie attributeForKey:QTMovieDurationAttribute] QTTimeValue];
QTTime theDiff = QTTimeDecrement(duration, currentPlayTime)
NSInterval timeInterval;
QTGetTimeInterval(theDiff, &timeInterval);
return [NSNumber numberWithDouble:(double)timeInterval];
}

Thank You Shane !!!

You last option works perfectly with one small change:

-(NSNumber *)secondsLeftToPlay:(QTMovie *)movie {
QTTime currentPlayTime = [[movie attributeForKey:QTMovieCurrentTimeAttribute] QTTimeValue];
QTTime duration = [[movie attributeForKey:QTMovieDurationAttribute] QTTimeValue];
QTTime theDiff = QTTimeDecrement(duration, currentPlayTime)
NSTimeInterval timeInterval;
QTGetTimeInterval(theDiff, &timeInterval);
return [NSNumber numberWithDouble:(double)timeInterval];
}

changed NSInterval to NSTimeInterval

Thank you once again !

Regards

P