• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
another n00b question -- addObserver weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

another n00b question -- addObserver weirdness


  • Subject: another n00b question -- addObserver weirdness
  • From: John Zorko <email@hidden>
  • Date: Tue, 11 Nov 2008 10:35:34 -0800


Hello, all ...

I'm experiencing weird issues with addObserver / removeObserver. I log when I add observers, as well as when I try to remove them, but I sometimes (not always) get an exception when I remove an observer:

2008-11-11 10:05:49.939 Magnatune[1382:20b] creating and starting audio engine to play mp3 stream http://he3.magnatune.com/all/02-La Febre (Uccellini)-Altri Stromenti.mp3
2008-11-11 10:05:49.962 Magnatune[1382:20b] audio engine created -- streamer is 90fe00
2008-11-11 10:05:49.970 Magnatune[1382:20b] adding observers ... 11d3b0
2008-11-11 10:05:49.983 Magnatune[1382:ae93] AudioStreamer - startInternal ...
2008-11-11 10:05:50.002 Magnatune[1382:20b] playing stream 1
2008-11-11 10:05:50.534 Magnatune[1382:20b] AudioStreamer -stop() called
2008-11-11 10:05:50.539 Magnatune[1382:20b] AudioStreamer -stop() finished


... the crash:

2008-11-11 10:05:51.538 Magnatune[1382:20b] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MagnatuneAppDelegate 0x11d3b0> for the key path "buffersEmpty" from <AudioStreamer 0x90fe00> because it is not registered as an observer.'

The MagnatuneAppDelegate address (11d3b0) is the same, so i'm adding observers to / removing observers from the same (and only) instance. Why does Cocoa then think that I didn't add the "buffersEmpty" observer when I clearly did?

The crash happens here, in the MagnatuneAppDelegate -stopStream method:

- (void)stopStream
{
	if (streamer)
	{
		[streamer removeObserver:self forKeyPath:@"buffersEmpty"];
		[streamer stop];
	}
}

... and MagnatuneAppDelegate spawns the streamer thread like this:

- (void)playStream:(UInt32)streamIndexToPlay
{
NSLog(@"playStream -- current thread ID: %x", [NSThread currentThread]);


.
.
.

if (streamIndexToPlay < [self countOfCurrentSongList])
{
self.donePlaying = false;
Song *streamToPlay = [self objectInCurrentSongListAtIndex:streamIndexToPlay];

NSString *address = @"http://he3.magnatune.com/all/";;
address = [address stringByAppendingString:streamToPlay.mp3];


		.
		.
		.

NSURL *url = [NSURL URLWithString:[address stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSLog(@"creating and starting audio engine to play mp3 stream %s", [[url description] UTF8String]);


streamer = [[AudioStreamer alloc] initWithURL:url];
NSLog(@"audio engine created -- streamer is %x", streamer);
NSLog(@"adding observers ... %x", self);
[streamer addObserver:self forKeyPath:@"isPlaying" options:0 context:nil];
[streamer addObserver:self forKeyPath:@"failed" options:0 context:nil];
[streamer addObserver:self forKeyPath:@"buffersEmpty" options:0 context:nil];
[streamer start];
}


	.
	.
	.
}

The AudioStreamer -start method is:

- (void)start
{
streamerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startInternal) object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(threadStopped)
name:NSThreadWillExitNotification
object:streamerThread];
[streamerThread start];

MagnatuneAppDelegate *appDelegate = (MagnatuneAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.playbackThreadFinished = false;
}


Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com











_______________________________________________

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


  • Follow-Ups:
    • Re: another n00b question -- addObserver weirdness
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: REĀ : a newbie question
  • Next by Date: Re: Play/Pause, rew/ff keys ...
  • Previous by thread: Re: NSSplitView can't expand once collapsed
  • Next by thread: Re: another n00b question -- addObserver weirdness
  • Index(es):
    • Date
    • Thread