为 android 扩展 MediaController
我正在为我正在开发的应用程序使用 VideoView
和 MediaController
。我只是想让 MediaController
出现在我的 VideoView
之上,但显然你不能很容易地做到这一点。我尝试对我的 VideoView
id 使用 setAnchorView
方法,但这不起作用。无论我做什么,MediaController
始终位于屏幕底部。
话虽如此,我做了一些研究,看起来好像我要扩展 MediaController,我可以更改位置和其他属性。我创建了一个新类:
package com.dop.mobilevforum;
import android.content.Context;
import android.widget.MediaController;
public class VFPlayer extends MediaController
{
public VFPlayer(Context context)
{
super(context);
}
}
在我的父类中:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.vforum);
controller = new VFPlayer(this);
vidPlayer = (VideoView) findViewById(R.id.vidPlayer);
vidPlayer.setMediaController(controller);
}
如果上面的内容正常工作,我的默认 MediaController
仍然会弹出并具有所有相同的功能。现在的问题是,我如何从我的 VFPlayer
类中实际重新定位控制器?
I am using a VideoView
and the MediaController
for an app I am working on. I simply wanted to have the MediaController
appear on top of my VideoView
but apparently you can't do that very easily. I attempted to use the setAnchorView
method to my VideoView
id, but that didn't work. No matter what I do, the MediaController
is always at the bottom of my screen.
With that said, I did some research and it looks as if I go about extending MediaController
, I can change position and other properties. I have created a new class:
package com.dop.mobilevforum;
import android.content.Context;
import android.widget.MediaController;
public class VFPlayer extends MediaController
{
public VFPlayer(Context context)
{
super(context);
}
}
and in my parent class:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.vforum);
controller = new VFPlayer(this);
vidPlayer = (VideoView) findViewById(R.id.vidPlayer);
vidPlayer.setMediaController(controller);
}
It the above is working, my default MediaController
still pops up and has all the same functionality. The question is now, how do I go about actually repositioning the controller from inside my VFPlayer
class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
控制 MediaController 位置的首选方法是通过 setAnchorView。不幸的是,每当加载新视频时,VideoView 似乎都会将此值覆盖为自身的父视图。为了解决这个问题,像下面这样的类应该可以工作
一旦你这样做了,你可以使用这个 MediaController 将 Anchor 设置为你想要的任何视图,而不必担心你的 VideoView 改变它。之后,只需在正确的位置获得视图来锚定它即可。
The preferred way to control the location of the MediaController is via setAnchorView. Unfortunately, the VideoView seems to override this value to be the parent view of itself whenever a new video is loaded. To counter act this, a class like the following should work
Once you do that, you can use this MediaController to set the Anchor to whichever view you desire without worrying about your VideoView changing it. After that, its just a matter of getting a view in the right place to anchor it too.
您应该能够重写
VFPlayer 类中的方法。从这里将视图/小部件放在您想要的位置。
You should be able to override the
method in your VFPlayer class. From here put the view/widget where you want it.
几个月前我对 Android 的了解是这样的:
当困难来临时,制作自己的组件。
我的意思是,很容易让你的组件布局,宽度为4或5个ImageButtons/Buttons,并将它们链接到VideoView组件功能(或SurfaceView以获得更好的控制)。
一些VideoView函数(摘自此处):
然后你可以一些带有按钮的布局,以便将它们放在您想要的位置,而不会出现尝试扩展像 V 这样的刚性组件的问题。
What i have learning some months ago about Android is this :
When difficultys come , make your own components .
What i mean , that is easy to make your components layout , width 4 or five ImageButtons/Buttons , and link them to the VideoView component functions (or SurfaceView for a better control ).
Some of the VideoView functions (extracted from here):
Then you can make some Layout with the buttons in order to put them where you want , without the problems of trying to extend a rigid component like V.