2009-04-29 2 views
0

방금 ​​iPhone 오디오 스트리밍 응용 프로그램을 개발했습니다 ... 이제 문제없이 오디오 파일을 재생할 수 있습니다. iPhone 네트워크가 3G에서 WiFi 및 viceversa로 전환 할 때 문제가 발생합니다. 네트워크를 전환하는 동안 스트림을 일시 중지해야합니다. 하지만 네트워크가 생길 때 재생을 재개 할 수 없었습니다. 아무도이 상황을 코드로 처리하는 방법을 가르쳐 줄 수 있습니까?iPhone에서 네트워크 스위칭을 처리하는 방법은 무엇입니까?

감사합니다, syam는 S

당신은 네트워크 상태 변화와 네트워크에 연결할 수 (그리고, 마찬가지로,이 NSNotification를 "재생"할 때 "일시 중지" NSNotification을 보내 다음 check Reachability status에 응용 프로그램을 설정하고 있습니다

답변

3

네트워크 상태 변화, 그리고 네트워크가 지금 다시 연결할 수) :

[[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]; 
} 
+0

안녕 알렉스, 당신 reply..I에 대한 감사는 오류 bytes..Whenever 스트림을 읽기 위해 CFNetwork에서 프레임 워크를 사용하고있는 readstream 통화 기능이 있습니다 발생 해고 당하지 않는다. 나는 연극을 다시 시작할 수 없다. 스트림 데이터를 가져 오기 위해 readstream 콜백을 재설정하는 방법을 알고 있습니까? –

+0

Google에서 "ASIHTTPRequest"를 검색하여 데이터 요청을 읽고 쉽게 다시 시작할 수있게하는 프레임 워크를 찾습니다. 이것은 도움이 될 수도 있고 도움이되지 않을 수도 있으며, 적어도 원시 소스 코드를 사용하여 Copsey가 어떻게 작동하는지 알 수 있습니다. –

관련 문제