获取MediaPlayer的状态

发布于 2024-10-31 15:28:33 字数 735 浏览 5 评论 0原文

在我的应用程序中,我从用户获取多个路径(1 个到图像、1 个到音轨、1 个到视频)并将它们存储在数据库中。当另一个活动开始查看文件时,不能保证文件仍位于这些路径中,甚至根本不存在,因为用户选择了它们并且可能已删除/移动了它们。因此,我需要能够检查这些路径上的文件是否有效。 我最初的计划是简单地捕获构造+设置每个对象时抛出的任何异常。 这是我用来查看每个异常的内容:

Image - a Drawable
Audio - a MediaPlayer
Video - a VideoView

我会通过向用户显示一个对话框来处理每个异常 但是,没有抛出任何异常,而是收到不同的错误消息

VideoView 显示自己的对话框,显示“抱歉,该视频无法播放”

其他人转到 LogCat:

04-10 23:34:43.174: ERROR/PlayerDriver(30): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
04-10 23:34:43.174: ERROR/MediaPlayer(271): error (1, -4)
04-10 23:34:43.365: ERROR/MediaPlayer(271): Error (1,-4)

关于如何获取 MediaPlayer 和 VideoView 或其他一些状态的任何想法检查路径的方法?

谢谢!

In my application I get multiple paths from the user (1 to an image, 1 to an audio track, and 1 to a video) and store them in a database. When another Activity is started to view the files, there isn't a guarantee the files will still be at those paths or even exist at all, since the user chose them and may have deleted/moved them. Therefore, I need to be able to check if the files at those paths are valid.
My original plan was to simply catch any Exceptions thrown when constructing + setting up each object.
Here's what I'm using to view each:

Image - a Drawable
Audio - a MediaPlayer
Video - a VideoView

I would have handled each Exception by showing a dialog to the user
However, no Exceptions are thrown and instead I get different error messages

The VideoView shows its own dialog saying "Sorry, this video cannot be played"

The others go to LogCat:

04-10 23:34:43.174: ERROR/PlayerDriver(30): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
04-10 23:34:43.174: ERROR/MediaPlayer(271): error (1, -4)
04-10 23:34:43.365: ERROR/MediaPlayer(271): Error (1,-4)

Any thoughts on how to get the state of MediaPlayer and VideoView or some other way to check the paths?

Thanks!

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

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

发布评论

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

评论(1

别念他 2024-11-07 15:28:33

您可以为 VideoViewMediaPlayer 设置 OnErrorListener。如果发生错误 - 您的侦听器将被调用。此外,您还可以使用 MediaPlayer 或使用 VideoView 检查音频和视频,因为它包含 MediaPlayer 来处理这两种情况。

顺便说一句,我认为 VideoView 的监听器实际上是在 VideoView 内的 MediaPlayer 对象中设置的

You can set OnErrorListener for VideoView and for MediaPlayer. If an error occurs - your listener will be called. Also, you can check both audio and video using MediaPlayer or using VideoView since it contains MediaPlayer to handle both anyway.

BTW, I think that the listener of VideoView is actually set in the MediaPlayer object within the VideoView

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