Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: How to change playback speed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to change playback speed




On Oct 19, 2006, at 1:00 AM, 山本 俊一 wrote:

I make command-line and audio playback program by using Objective-C and QTKit.
So, I could play audio file, but I can't change playback speed. My source code is
below.


#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>

@interface QTSoundTest:NSObject{
}
- (void)soundTest;
@end

@implementation QTSoundTest
- (void)soundTest{
   NSString *filepath=@"scratch0.aif";
   QTMovie *sound=[[QTMovie alloc] initWithFile:filepath error:nil];
   [sound setAttribute:[NSNumber numberWithFloat:0.5]
forKey:QTMovieRateAttribute];
   [sound play];
   (void)getchar();
}
@end

int main(void){
   NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
   id soundtest=[QTSoundTest alloc];
   [soundtest soundTest];
   [pool release];
   return -1;
}

Please tell me why my program doesn't change playback speed.

OK, but first a few comments.

id soundtest=[QTSoundTest alloc];

I think that this really should be:

   id soundtest = [[QTSoundTest alloc] init];

NSString *filepath=@"scratch0.aif";

-[QTMovie initWithFile:error:] is officially documented to take a full pathname. Partial pathnames sometimes work, but you should not count on that behavior.


[sound play];

This will start the sound playing, but the playback will cease after a second or so. The problem is that your command-line tool does not have a run loop, which is necessary for QTKit to continue to task the movie. Adding this line keeps the movie playing:


   [[NSRunLoop currentRunLoop] run];

Now to address the real issue. -[QTMovie play] essentially means: "start the movie playing at its preferred playback rate". So setting the movie rate before calling -play will not have the effect you desire. Either of the following should do what you want:

NSString *filepath=@"/Users/monroe/soundtester/foo.aac";
QTMovie *sound=[[QTMovie alloc] initWithFile:filepath error:nil];
[sound setAttribute:[NSNumber numberWithFloat:0.5] forKey:QTMovieRateAttribute];
[[NSRunLoop currentRunLoop] run];


or:

NSString *filepath=@"/Users/monroe/soundtester/foo.aac";
QTMovie *sound=[[QTMovie alloc] initWithFile:filepath error:nil];
[sound setAttribute:[NSNumber numberWithFloat:0.5] forKey:QTMoviePreferredRateAttribute];
[sound play];
[[NSRunLoop currentRunLoop] run];


Hope this helps,


Tim Monroe QuickTime Engineering

_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.