如何从媒体播放器的字节数组播放视频 [英] how to play video from byte array in media player
问题描述
我使用连接到我的Android设备的USB设备
i'm using usb device connected to my android device
此设备给我,包含视频帧缓冲
它的剂量持续。
this device send me a buffer that contain video frame it dose that continuously .
当我收到缓冲区我应该把特定的头成,并将其写入SD卡作为M4V视频文件。
when i receive the buffer i should put specific header into that and write it to sd card as m4v video file .
然后我要在媒体播放器播放
到目前为止,它工作正常,但我应该现场表演视频。一旦USB设备送我缓冲区我应该处理它,发挥它这样我就可以显示视频。
then i should play it in media player so far it works fine but i should show the video live . as soon as usb device send me the buffer i should process it and play it so i can show the video .
我的问题是如何在SD卡播放从字节的缓冲区视频文件没有专卖店呢?
my question is how to play a video file from byte buffer without store it in sd card ?
推荐答案
我知道这是一段时间,因为这个问题是问过,但我在那里我有一个视频传输流通过USB连接到同一情况。
I know this is awhile since the question was asked, but I am in the same situation where I have a video transport stream coming through a USB connection.
看起来你需要创建扩展一个MediaDataSource,并提供了 readAt()
和的getSize()$ C的数据源$ C>方法。
It looks like you need to create a data source that extends a MediaDataSource and provides the readAt()
and getSize()
methods.
我的理解是Android的MediaPlayer的,当你提供一个URL / URI作为数据源(通过的setDataSource()
,处理所有的网络下载数据或检索从存储中,并拥有自己的MediaDataSource玩家用户。
My understanding is Android's MediaPlayer, when you supply a URL/URI as a data source (through setDataSource()
, handles all the networking to download the data or retrieve it from storage, and has its own MediaDataSource the player users.
我的计划是创建一个从USB设备获取传输流的服务,并不断更新,我提供给MediaPlayer的。
My plan is to create a service that gets the transport stream from the USB device, and constantly update a custom MediaDataSource that I supply to the MediaPlayer.
<一个href=\"https://github.com/jpxiong/platform_cts/blob/dd40d693dfc3030cf8e9b0bf9f450f2276feb9ca/tests/tests/media/src/android/media/cts/TestMediaDataSource.java\"相对=nofollow>这里是我能找到的关于这个问题,这对使用带MediaPlayer的一个MediaDataSource测试书面测试的唯一的事情。他们从文件中读取到一个字节数组视频,然后使用该数组为 readAt()
和的getSize()
方法。
Here is the only thing I could find on the subject, which was a test written for testing using a MediaDataSource with the MediaPlayer. They read a video from a file into a byte array, and then use that array for the readAt()
and getSize()
methods.
只有其他资源,我能找到的人提供字符串的MediaPlayer的,但没有什么涉及到做自己的网络。另外,我很好奇视频络绎不绝的区别了,只是一个固定大小的视频。
Only other resources I could find are people supplying strings to the MediaPlayer, but nothing that involves doing their own networking. Also, I'm curious how a constant stream of video is different that just a fixed sized video.
编辑:我写了一篇博客文章MediaDataSource以及如何开始使用它。这里是链接。
I wrote a blog post about MediaDataSource and how to get started with it. Here is the link.
这篇关于如何从媒体播放器的字节数组播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!