Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

QTSoundFilePlayer



Hello all.

I'm just learning Cocoa and Objective-c, and I'm trying to make a
simple sound player out of the QTSoundFilePlayer classes found at http://www.snoize.com/


The class uses QT to decode the file, converts it using SoundConverter and plays it via an AudioUnit.

I want to refresh the UI for the user, namely a subclass of an NSSlider
and a text-field.

so for instance:

- (IBAction)myPlayAction:(id)sender
{
	[myMainPlayer play];
	[myMediaTimeField setFloatValue:[myMainPlayer duration]];
	[sender setTitle:[NSString stringWithFormat:@"%C%C", 0x275A, 0x275A]];
	[sender setAction:@selector(myPauseAction:)];
	
	myPlayerTimer = [[NSTimer scheduledTimerWithTimeInterval:0.2
target:self selector:@selector(refreshControls:) userInfo:nil
repeats:YES] retain];
	[[NSRunLoop currentRunLoop] addTimer: myPlayerTimer
forMode:NSModalPanelRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer: myPlayerTimer
forMode:NSEventTrackingRunLoopMode];
}

-(void)refreshControls:(NSTimer *)timer
{
	[myMediaTimeField setFloatValue:[myMainPlayer playbackPosition]];
	[myPlayerSlider setFloatValue:([myMainPlayer playbackPosition] /
[myMainPlayer duration])];
}



this seems to work OK, but the field doesn't refresh every 0.2
seconds(about every 1.5 seconds). Is it because I added the NSTimer to
the wrong thread(I know very little about threads)?



upon reading the class further I did this instead of the NSTimer:

I set MyDocument to be the delegate of the QTSoundFilePlayer. then I
added this code.

- (void)qtSoundFilePlayer:(QTSoundFilePlayer *)aPlayer
didPlayAudioBuffer:(AudioBuffer *)buffer
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	[myMediaTimeField setFloatValue:[myMainPlayer playbackPosition]];
	[myPlayerSlider setFloatValue:([myMainPlayer playbackPosition] /
[myMainPlayer duration])];
	[pool release];
}

I added the NSAutoreleasePool code because I was getting this error
repeatedly:

2004-12-27 08:49:49.811 SimpleBufferedPlayer[2434] ***
_NSAutoreleaseNoPool(): Object 0xa815130 of class NSCFNumber
autoreleased with no pool in place - just leaking
2004-12-27 08:49:49.822 SimpleBufferedPlayer[2434] ***
_NSAutoreleaseNoPool(): Object 0xa815130 of class NSCFNumber
autoreleased with no pool in place - just leaking

the text field refreshes about the same(around 1 second, isn't the
buffer read much more often than that?), but the number in the text
field seems to report the playbackPosition to an increment around
1.5-1.8. Any idea why?


thanks for any help, and happy holidays! Michael

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/coreaudio-api/email@hidden

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 © 2007 Apple Inc. All rights reserved.