Re: new to Cocoa -- threading question
Re: new to Cocoa -- threading question
- Subject: Re: new to Cocoa -- threading question
- From: Mike Abdullah <email@hidden>
- Date: Sun, 7 Sep 2008 11:14:52 +0100
Also, if you're just playing an MP3 file, look into using QTKit on the
main thread. Should be very much simpler and Objective C.
On 7 Sep 2008, at 02:35, John Michael Zorko wrote:
Hello, all ...
I'm new to Cocoa, and i'm trying to launch a thread. Yet, the app
bombs when I try, and the console says it's because the selector
isn't implemented:
2008-09-06 18:23:30.919 XXX[2363:20b] SEL: playMP3StreamThread
2008-09-06 18:23:30.927 XXX[2363:20b] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '*** -
[NSThread initWithTarget:selector:object:]: target does not
implement selector (*** -[XXXAppDelegate playMP3StreamThread])'
Yet, here it is -- i'm not understanding something obviously (the
example I saw looked easy enough):
@implementation XXXAppDelegate
.
.
.
- (void)playMP3StreamThread:(Song *)streamToPlay
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// initialize a mutex and condition so that we can block on buffers
in use.
pthread_mutex_init(&myData.mutex, NULL);
pthread_cond_init(&myData.cond, NULL);
OSStatus err = AudioFileStreamOpen(&myData, MyPropertyListenerProc,
MyPacketsProc,
kAudioFileAAC_ADTSType, &myData.audioFileStream);
if (err)
{
NSLog(@"AudioFileOStreamOpen error %d", err);
}
NSString *url = @"http://some_hostl/";
url = [url stringByAppendingString:streamToPlay.mp3];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:[url
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *connection = [[NSURLConnection alloc]
initWithRequest:request delegate:self];
if (connection)
{
receivedData = [[NSMutableData data] retain];
}
else
{
NSLog(@"can't connect to server");
}
[pool release];
}
- (void)playStream:(Song *)streamToPlay
{
NSLog(@"playing mp3 stream %s", [streamToPlay.mp3 UTF8String]);
// make sure current song play thread is stopped ...
// start a new thread with the new song ...
[NSThread detachNewThreadSelector:@selector(playMP3StreamThread)
toTarget:self withObject:streamToPlay];
}
What am I not grokking? Any pointers would be appreciated ...
Regards,
John
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden