【问题标题】:Php code to play audio streaming in android not work在android中播放音频流的php代码不起作用
【发布时间】:2013-01-08 15:05:13
【问题描述】:

你好我需要你的帮助我需要代码来播放音频流服务我需要的是当这个人从你的 android 移动下载 mp3 播放器进入 php 页面并在 android prederterminado 中发出声音时就像在这个页面中一样http://s2.viastreaming.net/mobile.php?port=6520 prefectamente 服务很好,但我会用这段代码做同样的事情,但我被告知问题是如果文件但没有听起来问题是什么,请如果有人知道这个主题..我需要你的帮助

<?php 

header("Content-type: audio/mpeg"); 
header("Transfer-Encoding: chunked");
header("Transfer-Encoding: none"); 
header("Connection: close");

$sock = fsockopen($streamname,$port); 

$streamname = "193.17.192.13"; //IP
$port = "80"; // PORT
$path = "/;stream.mp3"; 


fputs($sock, "GET $path HTTP/1.0\r\n");
fputs($sock, "Host: $ip\r\n"); 
fputs($sock, "User-Agent: WinampMPEG/2.8\r\n"); 
fputs($sock, "Accept: */*\r\n"); 
fputs($sock, "Icy-MetaData:1\r\n"); 
fputs($sock, "Connection: close\r\n\r\n");



fpassthru($sock); 

fclose($sock);
?> 

【问题讨论】:

    标签: php android audio-streaming live-streaming


    【解决方案1】:

    让我们仔细看看您从 PHP 脚本返回的数据。您的响应标头:

    HTTP/1.1 200 OK
    Date: Fri, 25 Jan 2013 04:19:16 GMT
    Server: Apache/2.2.16 (Debian)
    X-Powered-By: PHP/5.3.3-7+squeeze8
    icy-notice1: <BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>
    icy-notice2: SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>
    icy-name: Atmosfera 96.5 Grupo Emisoras Unidas
    icy-genre: Rock
    icy-url: http://www.atmosfera.fm
    icy-pub: 1
    icy-br: 64
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: audio/mpeg
    

    您可能遇到的问题是您正在使用分块编码发送流。更高版本的Android(我认为> 2.3)支持这一点,但之前不支持。分块编码也与许多其他播放器不兼容,例如 VLC 和 Winamp 的早期版本。

    简单的解决方案是确保您的服务器发送回不使用传输编码的 HTTP/1.0 响应。我还没有测试过,但既然你使用的是 Apache,试试这个:

    apache_setenv('force-response-1.0','true');
    

    另外,用Transfer-Encoding 删除你的两个header() 调用。

    完成后,测试并查看它是否有效。顺便说一句,您可以使用Wireshark 等工具轻松查看您的流发生了什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-16
      • 2019-03-18
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      相关资源
      最近更新 更多