【问题标题】:IceCast with iPhone Header issue带有 iPhone Header 问题的 IceCast
【发布时间】:2013-11-16 06:00:13
【问题描述】:

我正在尝试将 Icecast 服务器与我的 iPhone 应用程序一起使用。我正在为我的 icecast 服务器创建一个源客户端。目前我正在使用 NSURL 级别发送请求以向服务器创建挂载点。但我觉得这还不够。我必须使用任何其他核心库,如 CFNetworks 或 BSD 套接字。但我不确定。谁能帮我看看哪个库适合为 iPhone 实现 icecast。

第二件事是,当我实现 Icecast 请求的标头以创建挂载点时。我使用以下链接 - Icecast 2: protocol description, streaming to it using C#

但我无法发送SOURCE /mountpoint ICE/1.0,因为它没有密钥。

我发送它就像 -

 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]);
    }

我的响应是和 HTML 代码 -

<!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>

这是一个糟糕的回应。任何人都可以指导我如何发送一个整洁干净的请求并得到响应。在创建挂载点后,我也没有了解如何将 mp3 数据发送到服务器。如何创建流并将其发送到 icecast。

任何帮助将不胜感激。

【问题讨论】:

    标签: ios iphone objective-c icecast


    【解决方案1】:

    我使用GET 方法发送请求,这是错误的方法。 我用过-

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

    我可以在 icecast 服务器上创建挂载。

    我还添加了mp3文件数据来播放文件

        //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];
    

    它可以播放歌曲数据。但目前我不知道为什么它只播放一块数据。我正在研究将数据块添加到流中。

    【讨论】:

    • 检查您的服务器是否有错误“使用中的挂载点”服务器可能不允许再次写入数据。每次将新的缓冲区值写入服务器时,检查您是否没有创建套接字连接。这可能是问题所在。在您输入的代码中,其他一切看起来都很好。
    • @Devel,嘿,你能流式传输连续的数据块吗?我需要实现这一点。你能提供更多关于这个实现的细节吗?
    • 您需要确保以正确的时间发送数据。如果您使用即 libshout,它会为您处理这个(以及许多其他事情),但是您需要自己处理这个问题。
    猜你喜欢
    • 2010-12-07
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多