获取MediaPlayer的状态
在我的应用程序中,我从用户获取多个路径(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为
VideoView
和MediaPlayer
设置OnErrorListener
。如果发生错误 - 您的侦听器将被调用。此外,您还可以使用MediaPlayer
或使用VideoView
检查音频和视频,因为它包含MediaPlayer
来处理这两种情况。顺便说一句,我认为
VideoView
的监听器实际上是在VideoView
内的MediaPlayer
对象中设置的You can set
OnErrorListener
forVideoView
and forMediaPlayer
. If an error occurs - your listener will be called. Also, you can check both audio and video usingMediaPlayer
or usingVideoView
since it containsMediaPlayer
to handle both anyway.BTW, I think that the listener of
VideoView
is actually set in theMediaPlayer
object within theVideoView