Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get Video source path from VideoView

I have VideoView instance. I need to know video source path from it.

Is it possible? Can anybody help me?

My code from WebChromeClient class is:

    @Override
public void onShowCustomView(final View view, final CustomViewCallback callback) {
    super.onShowCustomView(view, callback);

    if (view instanceof FrameLayout) {
        final FrameLayout frame = (FrameLayout) view;
        if (frame.getFocusedChild() instanceof VideoView) {
            // get video view

            video = (VideoView) frame.getFocusedChild();
        }
    }
}

How to get video source path fron video object ?

like image 944
ihrupin Avatar asked Sep 06 '11 14:09

ihrupin


1 Answers

VideoView doesn't have getters for video path/Uri. Your only chance is to use reflection. The Uri is stored in private Uri mUri. To access it you can use:

Uri mUri = null;
try {
    Field mUriField = VideoView.class.getDeclaredField("mUri");
    mUriField.setAccessible(true);
    mUri = (Uri)mUriField.get(video);
} catch(Exception e) {}

Just bear in mind that a private field might be subject to change in future Android releases.

like image 145
Tomik Avatar answered Sep 19 '22 22:09

Tomik