Android从VideoView获取视频源路径
我有 VideoView 实例。我需要知道它的视频源路径。
是否可以?有人可以帮助我吗?
我来自 WebChromeClient 类的代码是:
@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();
}
}
}
如何从 video 对象获取视频源路径?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
VideoView
没有视频路径/Uri 的 getter。你唯一的机会就是使用反射。Uri
存储在private Uri mUri
中。要访问它,您可以使用:请记住,私有字段可能会在未来的 Android 版本中发生变化。
VideoView
doesn't have getters for video path/Uri. Your only chance is to use reflection. TheUri
is stored inprivate Uri mUri
. To access it you can use:Just bear in mind that a private field might be subject to change in future Android releases.
如果您不喜欢使用这样的私有方法,您可以覆盖
VideoView
中的setVideoUriMethod
:现在您可以根据需要访问 videoview 的 uri。希望有帮助。
You can override the
setVideoUriMethod
in theVideoView
if you do not like using private methods like this:Now you can access the uri of the videoview as needed. Hope that helps.
另一种选择是在视图标签上设置视频 Uri/路径并稍后检索。
当您播放/开始时
当您想检查正在播放的内容时
如果在适配器中使用,请记住清除标签。
Another alternative would be to set the video Uri/path on the tag of the view and retrieve later.
When you play/start
When you want to check what's playing
Just remember to clear out the tag if using in a adapter.