如何创建自定义媒体播放器来在 Android 中播放自定义编解码器?

发布于 2024-10-30 14:13:02 字数 833 浏览 2 评论 0原文

n00b 这里(第一个 Android 项目)。我获得了一个与 Android 固件版本集成的自定义视频编解码器。它是一个 .so 文件,包含一个继承自 MediaPlayerInterface 的类,以及一个自定义 MediaPlayerService 实现,用于从 create() 工厂函数返回适当文件类型的自定义编解码器类的实例。

我想将此编解码器用作视频播放器应用程序的一部分,该应用程序可以安装在固件中不包含编解码器的手机上,方法是将 .so 文件放入我的 libs/armeabi 文件夹中并通过 JNI 调用它。

这个问题的答案来看,我认为不可能在MediaPlayer 框架,我必须从头开始创建一个新的媒体播放器。首先,我用 Java 实现了一个 UI,并将其设置为使用自定义视图(而不是 VideoView),该视图扩展了 SurfaceView 并使用 MediaPlayer 类的实例来播放视频。然后我用自定义媒体播放器 Java 类替换了 MediaPlayer 的这个实例。我已经设置了 JNI 接口,模仿 android_media_MediaPlayer.cpp 的方式,并在 JNI 代码中调用 MediaPlayer C++ 类。现在我需要用自定义 C++ 媒体播放器类替换 that

这就是我开始遇到问题的地方。实现自定义播放器的推荐方法是什么?有吗?除了搜寻源代码之外,是否还有一些关于这些内容的在线文档?我可以使用该框架的多少部分以及我必须自己重新实现多少部分?我是否必须实现自己的 MediaPlayerService 等效项?

任何提示都非常感激。

n00b here (first Android project). I have been given a custom video codec that has been integrated with an Android firmware build. It's an .so file containing a class that inherits from MediaPlayerInterface, as well as a custom MediaPlayerService implementation to return instances of the custom codec class from the create() factory function for the appropriate file types.

I want to use this codec as part of a video player application that can be installed on phones that do not contain the codec in firmware, by putting the .so file in my libs/armeabi folder and calling it via JNI.

From the answer to this question I gather that it is not possible to do this within the MediaPlayer framework, and I have to create a new media player from the ground up. To start with, I implemented a UI in Java, and set it up to use a custom view (instead of VideoView), which extends SurfaceView and used an instance of the MediaPlayer class to play videos. Then I replaced this instance of MediaPlayer with a custom media player Java class. I've set up the JNI interface, mimicking the way android_media_MediaPlayer.cpp does it, and calling the MediaPlayer C++ class in the JNI code. Now I need to replace that with a custom C++ media player class.

This is where I'm starting to run into problems. What is the recommended approach for implementing a custom player? Is there one? Is there some online documentation for any of this stuff besides trawling through the source? How much of the framework can I use and how much do I have to reimplement myself? Will I have to implement my own equivalent to MediaPlayerService?

Any tips greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无需解释 2024-11-06 14:13:02

你可以查看Android的源代码来了解如何
Android已经用Java实现了MediaPlayer接口。你可以
遵循类似的思路。

MediaPlayer 类参考

You can look up the source code of Android to get an idea about how
Android have implemented the MediaPlayer interface in Java. You can
follow on similar lines.

MediaPlayer Class Reference

那伤。 2024-11-06 14:13:02

我希望你的编解码器不会太占用 CPU 资源。 Android 仅支持 H.264 的主要原因是(我猜)大多数设备都具有对此编解码器的硬件支持。其他编解码器需要由 CPU 处理,而 CPU 可能不够强大。

I hope your codec is not too CPU-intensive. The main reason Android supports only H.264 is (I guess) that there is hardware support for this codec in most devices. Other codecs will need to be processed by the CPU which will probably not be powerful enough.

迷荒 2024-11-06 14:13:02

为什么不使用 VLC 来代替呢?您可以获得源代码,支持各种格式。根据你的目的修剪它,剥皮,瞧,这就完成了。我知道他们现在实际上正在破解代码,你可以跳过它并帮助他们。

http://gigaom.com/video/vlc-for-android-demo-测试版/

why don't you use VLC instead? you can get the source code, supports every format. trim it down for your purpose, skin it, voila, c'est fini. i know they're actually hacking on the code now, you could jump it and help them out.

http://gigaom.com/video/vlc-for-android-demo-beta/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文