我无法在我的MediaPlayer应用程序中运行某个特定的流。我知道该应用程序可以工作,但当我决定更改我的流媒体服务时,新的URL无法工作。将这个URL插入网络浏览器确实有效。以下是我的相关代码:
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(在装有Android 4.3的三星Galaxy Nexus上运行):
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]
当我搜索内容类型时,我在维基百科上找到了这个:
…和.WMV(包含视频的文件,使用Windows Media音频和视频编解码器,MIME类型为“video/x-ms-asf”)
这是否意味着该流被编码为一个. WMV文件?(因此,不支持?)
编辑2
我得到保证,该流被编码为.MP3。我不知道为什么媒体播放器不会阅读它。
非常感谢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) {
}
使用这个 :
MediaPlayer Music = new MediaPlayer();
Music = MediaPlayer.create(G.context, Uri.parse("PUT YOUR URL HERE"));
Music.prepare();
Music.start();
当我一次又一次点击播放按钮时,它会同时播放多次。我想停止多重播放。这是代码: 媒体播放器和按钮的对象 按钮单击事件监听器以播放音频 按钮单击事件侦听器以停止音频 任何帮助都将不胜感激。谢谢
嗨,我为我的视频网站创建了一个WebView应用程序。网站的设计是为移动用户加载的混合体。只有与移动设备兼容的视频才会加载到混合动力上。玩家来自Vk,DailyMotion,YouTube和QuickTime。 (WebViewActivity.java) (main.xml) (Manifest.xml)
我有一个服务器端的webapp,提供文件上传和下载功能和一个Android应用程序,上传音乐文件到网站上,然后通过一些URL请求上传文件。 有什么建议吗?
当我尝试播放我的音乐时,Discord机器人不会播放音乐。它使用ytdl核心和ffmpeg。我的代码是: 每当我尝试播放歌曲时,都会发生以下错误: (节点:5180)未处理的PromisejectionWarning:错误:找不到FFmpeg/avconv!在功能上。getInfo(C:\Users\picar\Desktop\DiscordMusicBot\node\u modules\pris
我正在开发一个包含一些音频播放器的RecyclerView的应用程序。应用程序将下载。3gp文件(如果尚未下载)。 当我单击playAudio按钮时,音频未被播放。 这是我的适配器代码: 我怎样才能解决这个问题?
我一直在Flask中构建一个音乐符号应用程序。在后端,我使用Midiutil生成midi文件,在前端使用Midi.js播放文件。 我用Polyphone录制并构建了我的声音字体,并用soundfont_builder.rb.从sf2转换为JS 我现在面临的问题是soundfont_builder正在导致我不想要的音符长时间衰减。 有没有办法导航,使我的音符将播放不超过或短于midi文件定义的长度?