Janky
19-10-2009, 23:12
dunque...io ho questo diff...
come faccio a farlo funzionare correttamente?
diff –git a/Classes/Radio.h b/Classes/Radio.h
index 32f6b4a..5a358f7 100644
— a/Classes/Radio.h
+++ b/Classes/Radio.h
@@ -63,6 +63,9 @@ typedef struct {
UIAlertView *alert;
iPhoneRadioAppDelegate *appDelegate;
AQPlayerState audioState;
+
+ BOOL ICECast; //true when IceCast Stream, false for ShoutCast
+
}
-(id)init;
diff –git a/Classes/Radio.m b/Classes/Radio.m
index f661960..9f9b319 100644
— a/Classes/Radio.m
+++ b/Classes/Radio.m
@@ -341,12 +341,72 @@ void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
}
}
+//
+// Added By Sébastien Stormacq
+// ShoutCast support
+//
+
+-(int)parseShoutCastHeaders:(NSData*)buffer {
+
+ streamHeaders = [[NSMutableDictionary alloc] init];
+
+ NSString* rawHeader = [[NSString alloc] initWithData:buffer encoding:NSASCIIStringEncoding];
+ NSString* DELIMITER = @”\r\n”;
+ NSString* END_OF_HEADER_DELIMITER = @”\r\n\r\n”;
+
+ NSArray* lines = [rawHeader componentsSeparatedByString:DELIMITER];
+ for(NSString* line in lines) {
+ //NSLog(@”line = %@”, line);
+
+ //did we reach the last line ?
+ if ([line isEqualToString:@""])
+ break;
+ else {
+
+ NSRange range = [line rangeOfString:@":"];
+ if (range.location != NSNotFound) {
+ NSString* key = [line substringToIndex:range.location];
+ NSString* value = [line substringFromIndex:range.location+1];
+
+ [streamHeaders setValue:value forKey:key];
+ }
+ }
+ }
+
+ int result = [rawHeader rangeOfString:END_OF_HEADER_DELIMITER].location + [END_OF_HEADER_DELIMITER length];
+
+ NSLog(@”ICECAST Headers = %@”, streamHeaders);
+ NSLog(@”ICECAST startOfData = %d”, result);
+
+ [rawHeader release];
+
+ return result;
+}
+//
+// end of addition
+//
+
+#pragma mark NSURLConnection callBacks
+
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *u = (NSHTTPURLResponse *)response;
NSLog(@”HTTP Response = %u”, [u statusCode]);
-
- streamHeaders = [u allHeaderFields];
- [streamHeaders retain];
+
+ //
+ // Modified By Sébastien Stormacq
+ // ShoutCast support
+ //
+ if ([[u allHeaderFields] objectForKey:@”Ice-Audio-Info”] != nil) {
+ ICECast = YES;
+ streamHeaders = [u allHeaderFields];
+ [streamHeaders retain];
+ } else {
+ //likely a shout cast stream
+ ICECast = NO;
+ }
+ //
+ // end of modifications
+ //
NSLog(@”HTTP Response Headers = %@”, streamHeaders);
}
@@ -355,14 +415,42 @@ void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
// NSLog(@”didReceiveData %u bytes”, [data length]);
int length = [data length];
const char *bytes = (const char *)[data bytes];
+
+ int positionOfFirstData;
+
if (!icyInterval) {
- icyInterval = [[streamHeaders objectForKey:@"Icy-Metaint"] intValue];
+
+ if (ICECast) {
+ icyInterval = [[streamHeaders objectForKey:@"Icy-Metaint"] intValue];
+
+ //
+ // Added By Sébastien Stormacq
+ // ShoutCast support
+ //
+ } else {
+ //parse first bytes until empty line to read ShoutCast headers
+ positionOfFirstData = [self parseShoutCastHeaders:data];
+ icyInterval = [[streamHeaders objectForKey:@"icy-metaint"] intValue];
+
+ //for ICECast, remove the text header from first data block
+ NSRange range;
+ range.location = positionOfFirstData;
+ range.length = [data length] – positionOfFirstData;
+ //NSLog(@”range = %d, %d”, range.location, range.length);
+
+ NSData* subData = [data subdataWithRange:range];
+ length = [subData length];
+ bytes = (const char *)[subData bytes];
+ //NSLog(@”Pruned Data %u bytes\n—\n%@\n—”, length, [NSString stringWithCString:bytes length:length]);
+ }
+ //
+ // End of additions
+ //
+
NSLog(@”ICY INTERVAL = %u”, icyInterval);
- [self fillcurrentPacket:bytes withLength:length];
- }
- else {
- [self fillcurrentPacket:bytes withLength:length];
}
+
+ [self fillcurrentPacket:bytes withLength:length];
}
-(void)reconnect {
diff –git a/Classes/iPhoneRadioAppDelegate.m b/Classes/iPhoneRadioAppDelegate.m
index 2c4dd35..2eba747 100644
— a/Classes/iPhoneRadioAppDelegate.m
+++ b/Classes/iPhoneRadioAppDelegate.m
@@ -54,7 +54,9 @@
[window makeKeyAndVisible];
radio = [[Radio alloc] init];
- [radio connect:@"http://stream.radiojavan.com/radiojavan" withDelegate:self withGain:(0.5)];
+ //[radio connect:@"http://stream.radiojavan.com/radiojavan" withDelegate:self withGain:(0.5)];
+ [radio connect:@"http://stream.radiovazogasy.com:8001" withDelegate:self withGain:(0.5)];
+
}
è per modificare il codice di un'applicazione per iphone
grazie mille
come faccio a farlo funzionare correttamente?
diff –git a/Classes/Radio.h b/Classes/Radio.h
index 32f6b4a..5a358f7 100644
— a/Classes/Radio.h
+++ b/Classes/Radio.h
@@ -63,6 +63,9 @@ typedef struct {
UIAlertView *alert;
iPhoneRadioAppDelegate *appDelegate;
AQPlayerState audioState;
+
+ BOOL ICECast; //true when IceCast Stream, false for ShoutCast
+
}
-(id)init;
diff –git a/Classes/Radio.m b/Classes/Radio.m
index f661960..9f9b319 100644
— a/Classes/Radio.m
+++ b/Classes/Radio.m
@@ -341,12 +341,72 @@ void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
}
}
+//
+// Added By Sébastien Stormacq
+// ShoutCast support
+//
+
+-(int)parseShoutCastHeaders:(NSData*)buffer {
+
+ streamHeaders = [[NSMutableDictionary alloc] init];
+
+ NSString* rawHeader = [[NSString alloc] initWithData:buffer encoding:NSASCIIStringEncoding];
+ NSString* DELIMITER = @”\r\n”;
+ NSString* END_OF_HEADER_DELIMITER = @”\r\n\r\n”;
+
+ NSArray* lines = [rawHeader componentsSeparatedByString:DELIMITER];
+ for(NSString* line in lines) {
+ //NSLog(@”line = %@”, line);
+
+ //did we reach the last line ?
+ if ([line isEqualToString:@""])
+ break;
+ else {
+
+ NSRange range = [line rangeOfString:@":"];
+ if (range.location != NSNotFound) {
+ NSString* key = [line substringToIndex:range.location];
+ NSString* value = [line substringFromIndex:range.location+1];
+
+ [streamHeaders setValue:value forKey:key];
+ }
+ }
+ }
+
+ int result = [rawHeader rangeOfString:END_OF_HEADER_DELIMITER].location + [END_OF_HEADER_DELIMITER length];
+
+ NSLog(@”ICECAST Headers = %@”, streamHeaders);
+ NSLog(@”ICECAST startOfData = %d”, result);
+
+ [rawHeader release];
+
+ return result;
+}
+//
+// end of addition
+//
+
+#pragma mark NSURLConnection callBacks
+
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *u = (NSHTTPURLResponse *)response;
NSLog(@”HTTP Response = %u”, [u statusCode]);
-
- streamHeaders = [u allHeaderFields];
- [streamHeaders retain];
+
+ //
+ // Modified By Sébastien Stormacq
+ // ShoutCast support
+ //
+ if ([[u allHeaderFields] objectForKey:@”Ice-Audio-Info”] != nil) {
+ ICECast = YES;
+ streamHeaders = [u allHeaderFields];
+ [streamHeaders retain];
+ } else {
+ //likely a shout cast stream
+ ICECast = NO;
+ }
+ //
+ // end of modifications
+ //
NSLog(@”HTTP Response Headers = %@”, streamHeaders);
}
@@ -355,14 +415,42 @@ void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
// NSLog(@”didReceiveData %u bytes”, [data length]);
int length = [data length];
const char *bytes = (const char *)[data bytes];
+
+ int positionOfFirstData;
+
if (!icyInterval) {
- icyInterval = [[streamHeaders objectForKey:@"Icy-Metaint"] intValue];
+
+ if (ICECast) {
+ icyInterval = [[streamHeaders objectForKey:@"Icy-Metaint"] intValue];
+
+ //
+ // Added By Sébastien Stormacq
+ // ShoutCast support
+ //
+ } else {
+ //parse first bytes until empty line to read ShoutCast headers
+ positionOfFirstData = [self parseShoutCastHeaders:data];
+ icyInterval = [[streamHeaders objectForKey:@"icy-metaint"] intValue];
+
+ //for ICECast, remove the text header from first data block
+ NSRange range;
+ range.location = positionOfFirstData;
+ range.length = [data length] – positionOfFirstData;
+ //NSLog(@”range = %d, %d”, range.location, range.length);
+
+ NSData* subData = [data subdataWithRange:range];
+ length = [subData length];
+ bytes = (const char *)[subData bytes];
+ //NSLog(@”Pruned Data %u bytes\n—\n%@\n—”, length, [NSString stringWithCString:bytes length:length]);
+ }
+ //
+ // End of additions
+ //
+
NSLog(@”ICY INTERVAL = %u”, icyInterval);
- [self fillcurrentPacket:bytes withLength:length];
- }
- else {
- [self fillcurrentPacket:bytes withLength:length];
}
+
+ [self fillcurrentPacket:bytes withLength:length];
}
-(void)reconnect {
diff –git a/Classes/iPhoneRadioAppDelegate.m b/Classes/iPhoneRadioAppDelegate.m
index 2c4dd35..2eba747 100644
— a/Classes/iPhoneRadioAppDelegate.m
+++ b/Classes/iPhoneRadioAppDelegate.m
@@ -54,7 +54,9 @@
[window makeKeyAndVisible];
radio = [[Radio alloc] init];
- [radio connect:@"http://stream.radiojavan.com/radiojavan" withDelegate:self withGain:(0.5)];
+ //[radio connect:@"http://stream.radiojavan.com/radiojavan" withDelegate:self withGain:(0.5)];
+ [radio connect:@"http://stream.radiovazogasy.com:8001" withDelegate:self withGain:(0.5)];
+
}
è per modificare il codice di un'applicazione per iphone
grazie mille