Reputation: 4241
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!
Upvotes: 1
Views: 4993
Reputation: 137322
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
Upvotes: 2