tags:

views:

438

answers:

1

Hi All,

I just developed an iPhone audio streaming application...Now it can play audio files without any problems..The problem arise when the iPhone network switches from 3G to WiFi and viceversa..I need to pause the stream while network switches, but I couldn't able to resume playback when network comes..Can anybody point me to how to handle this situation with code?

Regards, Syam S

+3  A: 

You might set your app to check Reachability status and then send a "pause" NSNotification when the network status changes and the network is unreachable (and, likewise, a "play" NSNotification when the network status changes, and the network is now again reachable):

[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:@"kNetworkReachabilityChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseStreaming:) name:@"kPauseAudioStreamingIfPlaying" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseStreaming:) name:@"kPlayAudioStreamingIfPaused" object:nil];

- (void) reachabilityChanged:(id)sender {
  NetworkStatus reachabilityStatus = [[Reachability sharedReachability] internetConnectionStatus];
  if (reachabilityStatus == NotReachable)
     [[NSNotificationCenter defaultCenter] postNotificationName:@"kPauseAudioStreamingIfPlaying" object:nil];
  else 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"kPlayAudioStreamingIfPaused" object:nil];
}
Alex Reynolds
Hi Alex,Thanks for you reply..I am using CFnetwork frameworks for reading the stream bytes..Whenever any error occurs the readstream call function may not get fired..Thus I am unable to resume play..Do you know how to reset readstream callback to fetch stream data?
Syamoooo
Search Google on "ASIHTTPRequest" for a framework that more easily enables reading and restarting data requests. This might (or might not) help you, or might help you at least get started with some raw source code to see how Copsey does it.
Alex Reynolds