java 如何播放广播直播流 .asx video/x-ms-asf?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11584362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to play radio live stream .asx video/x-ms-asf?
提问by Eng.Fouad
Is there any 3rd-party library in Android or Java that can play radio live stream?
Android 或 Java 中是否有任何第三方库可以播放广播直播?
File extension: .asx
MIME type: video/x-ms-asf
Unfortunately, MediaPlayerdoes not support this format!
不幸的是,MediaPlayer不支持这种格式!
Here is the url of the live stream: http:// 38.96.148.75 /SunnahAudio
这是直播的网址:http://38.96.148.75/SunnahAudio
EDIT:
编辑:
I was able to convert .asf
file to .mp3
file by using JAVE:
我能够使用JAVE将.asf
文件转换为.mp3
文件:
File source = new File("sound.asf");
File target = new File("target.mp3");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(64000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
However, I'm streaming the .asf
online and I am not sure if I could stream the radio station, convert it to .mp3
, and immediately play it!
但是,我正在.asf
在线播放,我不确定是否可以播放广播电台,将其转换为.mp3
,然后立即播放!
EDIT2:
编辑2:
I offer 500+ rep for anyone provides a full and working solution to play .asf
live stream on Android. Basically, I want to play this radio station on Android (as xiialive
can do):
我为任何人提供了 500 多个代表,提供了.asf
在 Android 上播放实时流的完整且有效的解决方案。基本上,我想在 Android 上播放这个广播电台(xiialive
可以这样做):
http://38.96.148.75/SunnahAudio
采纳答案by vasart
If you open url of the stream in VLC player you can find out that it is an MMS
stream using WMA
codec mmsh://38.96.148.75/SunnahAudio?MSWMExt=.asf
Here is an open source project aacplayer-androidwhich uses libmms
and libffmpeg
to
get WMA content from mms://
stream and play it.
I hope it solves your problem.
如果您在 VLC 播放器中打开流的 url,您会发现它是MMS
使用WMA
编解码器的流mmsh://38.96.148.75/SunnahAudio?MSWMExt=.asf
这是一个开源项目aacplayer-android,它使用libmms
并libffmpeg
从mms://
流中获取 WMA 内容并播放它。
我希望它能解决你的问题。
回答by vArDo
I was able to successfully play your stream on Android using Vitamiolibrary. The biggest advantage of this lib is that it's API-compatible with Android SDK, so you'll just have to change imports in your code.
我能够使用Vitamio库在 Android 上成功播放您的流。该库的最大优点是它与 Android SDK 的 API 兼容,因此您只需更改代码中的导入即可。
One of Vitamino pluginsshould be present on given device to use the library. Simply open Vitamio Demoin Eclipse
and take a look at how to use it. Prompting user to install Vitamio pluginis included in demo.
给定设备上应存在一个Vitamino 插件才能使用该库。只需打开Vitamio演示中Eclipse
,并看看如何使用它。提示用户安装Vitamio 插件包含在演示中。
I was able to play your stream with this code:
我能够使用以下代码播放您的流:
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.os.Bundle;
public class VideoViewDemo extends Activity {
private String path = "mmsh://38.96.148.75/SunnahAudio";
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
As you can see - similar to using VideoView
from Android SDK. Pretty much the only difference are imports.
如您所见 - 类似于VideoView
从 Android SDK 使用。几乎唯一的区别是进口。
The only difference to be noted is that I was unable to use httplink, so I had to use the real streaming URL with mmshprotocol (opened in VLC- similar to what @vasart did).
唯一需要注意的区别是我无法使用http链接,所以我必须使用带有mmsh协议的真实流 URL (在VLC 中打开- 类似于@vasart 所做的)。
For reference you can take a look at logs from successful playback.
作为参考,您可以查看成功播放的日志。