Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:MediaPlayer赢了';t流MP3_Android_Media Player_Android Mediaplayer - Fatal编程技术网

Android 安卓:MediaPlayer赢了';t流MP3

Android 安卓:MediaPlayer赢了';t流MP3,android,media-player,android-mediaplayer,Android,Media Player,Android Mediaplayer,我无法在我的MediaPlayer应用程序中使用特定流。我知道这个应用程序可以工作,但当我决定改变我的流媒体服务时,新的URL就不能工作了。将此URL插入web浏览器确实有效。这是我的相关代码: String url = "http://smoke.wavestreamer.com:7562/listen.asx?sid=1"; mediaPlayer.setOnPreparedListener(this); // ...and other listeners... mediaPlayer.se

我无法在我的MediaPlayer应用程序中使用特定流。我知道这个应用程序可以工作,但当我决定改变我的流媒体服务时,新的URL就不能工作了。将此URL插入web浏览器确实有效。这是我的相关代码:

String url = "http://smoke.wavestreamer.com:7562/listen.asx?sid=1";
mediaPlayer.setOnPreparedListener(this); // ...and other listeners...
mediaPlayer.setDataSource(url);
mediaPlayer.prepareAsync();
然后,在onPrepared()中:

这是我的LogCat(在我的三星Galaxy Nexus Android 4.3上运行):

当我搜索内容类型时,我在:

…和.WMV(包含视频的文件,使用Windows Media音频和 视频编解码器,MIME类型为“Video/x-ms-asf”)

这是否意味着流被编码为.WMV文件?(因此不受支持吗?)

编辑2

我已经得到保证,该流被编码为.MP3。我不知道MediaPlayer为什么不读它。

使用这个:

            MediaPlayer Music = new MediaPlayer();
            Music = MediaPlayer.create(G.context, Uri.parse("PUT YOUR URL HERE"));
            Music.prepare();
            Music.start();
非常感谢on-so,尽管URL坚持其内容类型为媒体,但我将其解析为文本文件,发现它是一个文本文件——基本上是一个包含实际媒体流链接的播放列表

对于可能遇到此问题的任何其他人,以下是我用来解析URL并了解实际流媒体链接的代码:

        String url = "http://smoke.wavestreamer.com:7562/listen.asx";
        String charset = "UTF-8";
        String param1 = "1";

        try {
            String query = String.format("sid=%s", URLEncoder.encode(param1, charset));

            // Open a connection and InputStream to URL
            URLConnection connection = new URL(url + "?" + query).openConnection();
            connection.setRequestProperty("Accept-Charset", charset);
            InputStream response = connection.getInputStream();

            // Get status
            int status = ((HttpURLConnection) connection).getResponseCode();
            System.out.println("HttpURLConnection STATUS = " + status);

            // Get headers
            for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
                System.out.println(header.getKey() + "=" + header.getValue());
            }

            // Read response InputStream
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response/*, charset*/))) {
                System.out.println("Reading 'response' InputStream:");
                for (String line; (line = reader.readLine()) != null;) {
                    System.out.println(line);
                }
            }

        } catch (UnsupportedEncodingException e) {
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
stringurl=”http://smoke.wavestreamer.com:7562/listen.asx";
字符串charset=“UTF-8”;
字符串param1=“1”;
试一试{
字符串查询=String.format(“sid=%s”,URLEncoder.encode(param1,charset));
//打开连接并将流输入到URL
URLConnection connection=新URL(URL+“?”+查询).openConnection();
setRequestProperty(“接受字符集”,字符集);
InputStream响应=connection.getInputStream();
//获得地位
int status=((HttpURLConnection)connection.getResponseCode();
System.out.println(“HttpURLConnection STATUS=“+STATUS”);
//获取标题
for(条目标题:connection.getHeaderFields().entrySet()){
System.out.println(header.getKey()+“=”+header.getValue());
}
//读取响应输入流
try(BufferedReader=new BufferedReader(new InputStreamReader(response/*,charset*/)){
System.out.println(“读取‘响应’输入流:”);
for(字符串行;(line=reader.readLine())!=null;){
系统输出打印项次(行);
}
}
}捕获(不支持的编码异常e){
}捕获(格式错误){
}捕获(IOE异常){
}

我试过了,但没有成功。得到了完全相同的响应,除了logcat输出中的这一细微变化:
D/MediaPlayer:无法在客户端打开文件,正在尝试服务器端
确保已声明INTERNET权限和WAKE__LOCK权限。我查看了上的MediaPlayer源代码,发现错误消息(“无法打开文件…”)仅当尝试将URI用作数据源时存在
IOException
SecurityException
时才会调用。不幸的是,这两个
catch
块都是空的,因此我无法获得更具体的错误消息。
null=[HTTP/1.1 200 OK]
Connection=[close]
Content-Length=[244]
Content-Type=[video/x-ms-asf]
            MediaPlayer Music = new MediaPlayer();
            Music = MediaPlayer.create(G.context, Uri.parse("PUT YOUR URL HERE"));
            Music.prepare();
            Music.start();
        String url = "http://smoke.wavestreamer.com:7562/listen.asx";
        String charset = "UTF-8";
        String param1 = "1";

        try {
            String query = String.format("sid=%s", URLEncoder.encode(param1, charset));

            // Open a connection and InputStream to URL
            URLConnection connection = new URL(url + "?" + query).openConnection();
            connection.setRequestProperty("Accept-Charset", charset);
            InputStream response = connection.getInputStream();

            // Get status
            int status = ((HttpURLConnection) connection).getResponseCode();
            System.out.println("HttpURLConnection STATUS = " + status);

            // Get headers
            for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
                System.out.println(header.getKey() + "=" + header.getValue());
            }

            // Read response InputStream
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response/*, charset*/))) {
                System.out.println("Reading 'response' InputStream:");
                for (String line; (line = reader.readLine()) != null;) {
                    System.out.println(line);
                }
            }

        } catch (UnsupportedEncodingException e) {
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }