1

I am trying to use Icecast server with my iPhone app. I am creating a source client for my icecast server. Currently I am using NSURL level for sending request to create a mount point to the server. But as I felt that its not sufficient. I have to use any other core library like CFNetworks or BSD Sockets. But I am not sure. Can any one please help me out that which library is suitable to implement icecast for iPhone.

The second thing is that when I am implementing a header for Icecast request to create mountpoint. I using following link - Icecast 2: protocol description, streaming to it using C#

But I am not able to send SOURCE /mountpoint ICE/1.0 because its without key.

I am sending it like -

 NSMutableString *requestString = [NSMutableString stringWithFormat:@"http://192.168.1.99:8000"];

    NSLog(@"Request String = %@", requestString);


    NSURL *url = [NSURL URLWithString:requestString];
    NSMutableURLRequest *requestURL = [NSMutableURLRequest requestWithURL:url];
    [requestURL setHTTPMethod:@"GET"];
    [requestURL addValue:@"SOURCE /mp3test ICE/1.0" forHTTPHeaderField:@"SOURCE"];
    [requestURL addValue:@"audio/mpeg" forHTTPHeaderField: @"Content-Type"];
    [requestURL setValue:@"Basic c291cmNlOmhhY2ttZQ==" forHTTPHeaderField:@"Authorization"];
    [requestURL setValue:@"This is my server name" forHTTPHeaderField:@"ice-name"];
    [requestURL setValue:path forHTTPHeaderField:@"ice-url"];
    [requestURL setValue:@"Rock" forHTTPHeaderField:@"ice-genre"];
    [requestURL setValue:@"128" forHTTPHeaderField:@"ice-bitrate"];
    [requestURL setValue:@"0" forHTTPHeaderField:@"ice-private"];
    [requestURL setValue:@"1" forHTTPHeaderField:@"ice-public"];
    [requestURL setValue:@"This is my server description" forHTTPHeaderField:@"ice-description"];
    [requestURL setValue:@"ice-samplerate=44100;ice-bitrate=128;ice-channels=2" forHTTPHeaderField:@"ice-audio-info"];

    NSLog(@"Request URL Value = %@",requestURL);

    NSURLResponse *response;
    NSError *error;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:requestURL returningResponse:&response error:&error];

    if(error !=  nil){
         NSLog(@"%@",[error description]);
    }

My Response is and HTML code -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Icecast Streaming Media Server</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<h2>Icecast2 Status</h2>
<br><div class="roundcont">
<div class="roundtop"><img src="/corner_topleft.jpg" class="corner" style="display: none"></div>
<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="4"><tr><td bgcolor="#656565">
<a class="nav" href="admin/">Administration</a><a class="nav" href="status.xsl">Server Status</a><a class="nav" href="server_version.xsl">Version</a>
</td></tr></table>
<div class="roundbottom"><img src="/corner_bottomleft.jpg" class="corner" style="display: none"></div>
</div>

<br><br>&nbsp;


<div class="poster">Support icecast development at <a class="nav" target="_blank" href="http://www.icecast.org">www.icecast.org</a>
</div>
</body>
</html>

Its a bad response. Can any one please guide me that how can I send a neat and clean request and get response. I also did not get that how to send mp3 data to server after creating a mountpoint. How to create a stream and send it to icecast.

Any help will be appreciated.

Community
  • 1
  • 1
Devel
  • 449
  • 3
  • 9

1 Answers1

0

I was sending request using GET method which was a wrong way. I used -

[requestURL setHTTPMethod:@"SOURCE /mountpoint ICE/1.0"];.

I am able to create mount at icecast server.

I also added mp3 file data to play the file like

    //get data from the file url so we can start recording with some file
    NSData *audioData = [NSData dataWithContentsOfURL:fileURL];

    //add audio to stream and add the stream to request for sending data
    NSInputStream *inputStream = [NSInputStream inputStreamWithData:audioData];
    [request setHTTPBodyStream:inputStream];

Its able to play the song data. But currently I don't know why its play only a single chunk of data. I am researching to add chunks of data to stream.

Devel
  • 449
  • 3
  • 9
  • Check your server for an error 'mountpoint in use' there is a possibility that the server doesnt allow the data to be written again. Check if you are not creating a socket connection everytime a new buffer value is written to the server.This could be the problem. Everything else looks fine in the code you've put. – koherent Dec 02 '13 at 07:19
  • @Devel, Hey were you able to stream continuous chunks of data? I need to implement this. Can you give more details about the implementation of this? – Pavan Kotesh Dec 18 '14 at 14:47
  • You need to make sure to send it data with correct timing. If you use i.e. libshout, it will handle this for you (and many other things), but else you need to take care of this yourself. – ePirat Jul 02 '15 at 10:21