流式传输到 Android MediaPlayer
我正在尝试在我的应用程序中编写一个轻量级 HTTP
服务器,以将动态生成的 MP3
数据提供给内置 Android
MediaPlayer
。我无权将我的内容存储在SD 卡
上。
我的输入数据本质上是无限长度的。我告诉 MediaPlayer 它的数据源基本上应该类似于“http://localhost/myfile.mp3”。我设置了一个简单的服务器,等待 MediaPlayer
发出此请求。但是,MediaPlayer
不太配合。首先,它发出一个 HTTP GET
并尝试获取整个文件。如果我们尝试简单地将数据转储到套接字中,则会超时,因此我们尝试使用 HTTP Range 标头以块的形式写入数据。 MediaPlayer 不喜欢这样,并且不会继续请求后续块。
有没有人成功地将数据直接流式传输到 MediaPlayer 中?我是否需要实施 RTSP
或 Shoutcast
服务器?我只是缺少一个关键的 HTTP header
吗?我应该在这里使用什么策略?
I'm trying to write a light-weight HTTP
server in my app to feed
dynamically generated MP3
data to the built-in Android
MediaPlayer
. I am not permitted to store my content on the SD card
.
My input data is essentially of an infinite length. I tell MediaPlayer
that its data source should basically be something like "http://localhost/myfile.mp3"
. I've a simple server set up that waits for MediaPlayer
to make this request. However, MediaPlayer
isn't very cooperative. At first, it makes an HTTP GET
and tries to grab the whole file. It times out if we try and simply dump data into the socket
so we tried using the HTTP
Range header to write data in chunks. MediaPlayer
doesn't like this and doesn't keep requesting the subsequent chunks.
Has anyone had any success streaming data directly into MediaPlayer
? Do I need to implement an RTSP
or Shoutcast
server instead? Am I simply missing a critical HTTP header
? What strategy should I use here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)