mattgallagher / AudioStreamer

A streaming audio player class (AudioStreamer) for Mac OS X and iPhone.
http://cocoawithlove.com
1.93k stars 553 forks source link

m3u and pls file #61

Open bettocr opened 11 years ago

bettocr commented 11 years ago

Greetings!

I wonder if you can use an m3u or pls file, I've tried everything and I've failed.

thanks

ndane commented 11 years ago

Look at the structure of the files, they should contain the URL for the actual stream.

Try curl http://www.supremeradio.it/supreme.pls in Terminal

confact commented 11 years ago

I have a simple function which get the first adress in the pls and return it. I have one for m3u too but this maybe makes more clear when you can see a okay example.

- (NSString*)getAddressFromPLS:(NSURL *)url
{
    NSString *plsurl = @"";
    NSError* error = nil;
    NSString *fileContents = [NSString stringWithContentsOfURL: url 
                                                      encoding: NSUTF8StringEncoding 
                                                         error: &error];
    if(![fileContents hasPrefix:@"ICY 404"]) {
        if(fileContents && !error) {
            NSMutableArray *lines = [fileContents componentsSeparatedByString:@"\n"];
            for(int i = 0;i<[lines count];i++)
            {
                if([[lines objectAtIndex:i] hasPrefix:@"File1="])
                {
                    plsurl = [[lines objectAtIndex:i] stringByReplacingOccurrencesOfString:@"File1=" withString:@""];
                }
            }
        }
    }
    else
    {
        plsurl = @"";  
    }
    NSLog(@"Address: %@", plsurl);
    return plsurl;
}
douster commented 11 years ago

在 2013年6月12日星期三,Håkan Nylén 写道:

I have a simple function which get the first adress in the pls and return it. I have one for m3u too but this maybe makes more clear when you can see a okay example.

  • (NSString)getAddressFromPLS:(NSURL )url{ NSString plsurl = @""; NSError error = nil; NSString fileContents = [NSString stringWithContentsOfURL: url encoding: NSUTF8StringEncoding error: &error]; if(![fileContents hasPrefix:@"ICY 404"]) { if(fileContents && !error) { NSMutableArray lines = [fileContents componentsSeparatedByString:@"\n"]; for(int i = 0;i<[lines count];i++) { if([[lines objectAtIndex:i] hasPrefix:@"File1="]) { plsurl = [[lines objectAtIndex:i] stringByReplacingOccurrencesOfString:@"File1=" withString:@""]; } } } } else { plsurl = @""; } NSLog(@"Address: %@", plsurl); return plsurl;}

— Reply to this email directly or view it on GitHubhttps://github.com/mattgallagher/AudioStreamer/issues/61#issuecomment-19313298 .