我无法在我的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():
mediaPlayer.start();
这是我的LogCat(在我的Samsung Galaxy Nexus上使用Android 4.3运行):
01-23 14:32:08.994 8726-8726/com.mycompany.myapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-23 14:32:08.994 8726-8726/com.mycompany.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11370: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-23 14:32:08.994 8726-8726/com.mycompany.myapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-23 14:32:08.994 8726-8726/com.mycompany.myapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-23 14:32:08.994 8726-8726/com.mycompany.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11376: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-23 14:32:08.994 8726-8726/com.mycompany.myapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-23 14:32:09.002 8726-8726/com.mycompany.myapp I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-23 14:32:09.002 8726-8726/com.mycompany.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 9064: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-23 14:32:09.002 8726-8726/com.mycompany.myapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-23 14:32:09.017 8726-8726/com.mycompany.myapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-23 14:32:09.017 8726-8726/com.mycompany.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 377: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-23 14:32:09.025 8726-8726/com.mycompany.myapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-23 14:32:09.025 8726-8726/com.mycompany.myapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-23 14:32:09.025 8726-8726/com.mycompany.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 399: Landroid/content/res/TypedArray;.getType (I)I
01-23 14:32:09.025 8726-8726/com.mycompany.myapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-23 14:32:09.244 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Binding to service
01-23 14:32:09.244 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ in startAndBindToService()
01-23 14:32:09.533 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ service.onStartCommand()
01-23 14:32:09.533 8726-8726/com.mycompany.myapp D/MediaPlayerService﹕ onStartCommand()
01-23 14:32:09.541 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ intent.getAction() is null (started from MainActivity); returning now
01-23 14:32:09.799 8726-8726/com.mycompany.myapp D/libEGL﹕ loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
01-23 14:32:09.892 8726-8726/com.mycompany.myapp D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
01-23 14:32:09.900 8726-8726/com.mycompany.myapp D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
01-23 14:32:10.088 8726-8726/com.mycompany.myapp D/OpenGLRenderer﹕ Enabling debug mode 0
01-23 14:32:10.088 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Bound to service
01-23 14:32:10.096 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Initializing service.
01-23 14:32:10.096 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ setting up mediaPlayer
01-23 14:32:10.408 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Service set to run in foreground.
01-23 14:32:10.510 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ WifiLock acquired.
01-23 14:32:10.635 8726-8726/com.mycompany.myapp I/Choreographer﹕ Skipped 31 frames! The application may be doing too much work on its main thread.
01-23 14:32:10.931 8726-8739/com.mycompany.myapp E/MediaPlayer﹕ error (1, -2147483648)
01-23 14:32:11.041 8726-8726/com.mycompany.myapp E/MediaPlayer﹕ Error (1,-2147483648)
01-23 14:32:11.041 8726-8726/com.mycompany.myapp E/MyMediaPlayer﹕ There has been an error of type MEDIA_ERROR_UNKNOWN, with no extras
01-23 14:32:11.041 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ There was an error initializing media player
01-23 14:32:11.056 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Restarting after error
01-23 14:32:11.056 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Initializing service.
01-23 14:32:11.056 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ setting up mediaPlayer
01-23 14:32:11.221 8726-8726/com.mycompany.myapp D/dalvikvm﹕ GC_FOR_ALLOC freed 231K, 3% free 9144K/9412K, paused 136ms, total 137ms
01-23 14:32:11.517 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ resetting mediaPlayer
01-23 14:32:11.627 8726-8856/com.mycompany.myapp E/MediaPlayer﹕ error (1, -2147483648)
01-23 14:32:11.838 8726-8726/com.mycompany.myapp E/MediaPlayer﹕ Error (1,-2147483648)
01-23 14:32:11.846 8726-8726/com.mycompany.myapp E/MyMediaPlayer﹕ There has been an error of type MEDIA_ERROR_UNKNOWN, with no extras
01-23 14:32:11.846 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ There was an error initializing media player
01-23 14:32:11.861 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Restarting after error
01-23 14:32:11.861 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Initializing service.
01-23 14:32:11.861 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ setting up mediaPlayer
01-23 14:32:11.900 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Service set to run in foreground.
01-23 14:32:11.971 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ resetting mediaPlayer
01-23 14:32:11.978 8726-8739/com.mycompany.myapp E/MediaPlayer﹕ error (1, -107)
01-23 14:32:12.064 8726-8726/com.mycompany.myapp E/MediaPlayer﹕ Error (1,-107)
01-23 14:32:12.064 8726-8726/com.mycompany.myapp E/MyMediaPlayer﹕ There has been an error of type MEDIA_ERROR_UNKNOWN, with no extras
01-23 14:32:12.064 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ There was an error initializing media player
01-23 14:32:12.080 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Restarting after error
01-23 14:32:12.080 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Initializing service.
01-23 14:32:12.080 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ setting up mediaPlayer
01-23 14:32:12.166 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Service set to run in foreground.
01-23 14:32:12.306 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ resetting mediaPlayer
01-23 14:32:12.471 8726-8740/com.mycompany.myapp E/MediaPlayer﹕ error (1, -2147483648)
01-23 14:32:12.525 8726-8726/com.mycompany.myapp E/MediaPlayer﹕ Error (1,-2147483648)
01-23 14:32:12.525 8726-8726/com.mycompany.myapp E/MyMediaPlayer﹕ There has been an error of type MEDIA_ERROR_UNKNOWN, with no extras
01-23 14:32:12.525 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ There was an error initializing media player
01-23 14:32:12.541 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Restarting after error
01-23 14:32:12.541 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Initializing service.
01-23 14:32:12.541 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ setting up mediaPlayer
01-23 14:32:12.603 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Service set to run in foreground.
01-23 14:32:12.666 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ resetting mediaPlayer
01-23 14:32:12.674 8726-8740/com.mycompany.myapp E/MediaPlayer﹕ error (1, -107)
01-23 14:32:12.721 8726-8726/com.mycompany.myapp E/MediaPlayer﹕ Error (1,-107)
01-23 14:32:12.728 8726-8726/com.mycompany.myapp E/MyMediaPlayer﹕ There has been an error of type MEDIA_ERROR_UNKNOWN, with no extras
01-23 14:32:12.728 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ There was an error initializing media player
01-23 14:32:12.744 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Restarting after error
01-23 14:32:12.744 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Initializing service.
01-23 14:32:12.744 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ setting up mediaPlayer
01-23 14:32:12.806 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ Service set to run in foreground.
01-23 14:32:12.869 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ resetting mediaPlayer
01-23 14:32:13.158 8726-8739/com.mycompany.myapp E/MediaPlayer﹕ error (1, -2147483648)
01-23 14:32:14.619 8726-8726/com.mycompany.myapp D/MyMediaPlayer﹕ resetting mediaPlayer
01-23 14:32:23.588 9136-9136/com.mycompany.myapp D/MyMediaPlayer﹕ service.onStartCommand()
01-23 14:32:23.588 9136-9136/com.mycompany.myapp D/MediaPlayerService﹕ onStartCommand()
01-23 14:32:23.588 9136-9136/com.mycompany.myapp D/MyMediaPlayer﹕ intent is null (restarted after service crashed); returning now
01-23 14:38:12.939 9136-9136/com.mycompany.myapp D/dalvikvm﹕ GC_EXPLICIT freed 49K, 1% free 8874K/8960K, paused 5ms+4ms, total 47ms
01-23 14:39:58.627 10507-10507/com.mycompany.myapp D/MyMediaPlayer﹕ service.onStartCommand()
01-23 14:39:58.627 10507-10507/com.mycompany.myapp D/MediaPlayerService﹕ onStartCommand()
01-23 14:39:58.627 10507-10507/com.mycompany.myapp D/MyMediaPlayer﹕ intent is null (restarted after service crashed); returning now
01-23 14:45:06.166 11567-11567/com.mycompany.myapp D/MyMediaPlayer﹕ service.onStartCommand()
01-23 14:45:06.166 11567-11567/com.mycompany.myapp D/MediaPlayerService﹕ onStartCommand()
01-23 14:45:06.166 11567-11567/com.mycompany.myapp D/MyMediaPlayer﹕ intent is null (restarted after service crashed); returning now
01-23 14:48:12.556 11567-11567/com.mycompany.myapp D/dalvikvm﹕ GC_EXPLICIT freed 40K, 1% free 8874K/8952K, paused 5ms+3ms, total 42ms
01-23 14:50:54.744 11567-11567/com.mycompany.myapp D/dalvikvm﹕ GC_EXPLICIT freed 1K, 1% free 8873K/8952K, paused 3ms+3ms, total 32ms
01-23 14:52:52.205 11567-11567/com.mycompany.myapp D/dalvikvm﹕ GC_EXPLICIT freed <1K, 1% free 8873K/8952K, paused 4ms+3ms, total 36ms
有什么想法吗?
修改
我做了一些挖掘并将HttpURLConnection设置为上面提供的链接。当我解析标题时,这就是我找到的(key = value):
null=[HTTP/1.1 200 OK]
Connection=[close]
Content-Length=[244]
Content-Type=[video/x-ms-asf]
当我对Content-Type进行搜索时,我在Wikipedia上找到了这个:
...和.WMV(包含视频的文件,使用Windows Media Audio和 视频编解码器,MIME类型为“video / x-ms-asf”)
这是否意味着流被编码为.WMV文件? (因此,不受支持?)
编辑2
我确信该流被编码为.MP3。我不知道为什么MediaPlayer不会读它。
答案 0 :(得分:0)
使用它:
MediaPlayer Music = new MediaPlayer();
Music = MediaPlayer.create(G.context, Uri.parse("PUT YOUR URL HERE"));
Music.prepare();
Music.start();
答案 1 :(得分:0)
非常感谢this answer关于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) {
}