- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我尝试在 SurfaceView
之上显示一个 VideoView
。但它不可见但对点击有反应(MediaController 出现并播放声音)。视频似乎在 SurfaceView
后面播放,所以我也尝试使用 setZOrderMediaOverlay()
和/或 setZOrderOnTop()
但没有任何改变
当我转到主屏幕时,我在淡入淡出的动画中看到了一瞬间的 VideoView,所以它确实存在。
我用 xml 布局尝试过,也完全以编程方式尝试过,但没有任何效果。
这是我的 Activity :
public class VideoTest extends Activity {
private RelativeLayout mLayout;
private VideoView mVideo;
private Handler mHandler;
private FrameLayout mFrameLayout;
private SurfaceView mSurfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFrameLayout = new FrameLayout(this);
mFrameLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mLayout = new RelativeLayout(this);
mLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mVideo = new VideoView(this);
mVideo.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mSurfaceView = new SurfaceView(this);
mSurfaceView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mSurfaceView.setZOrderMediaOverlay(false);
mSurfaceView.setZOrderOnTop(false);
mFrameLayout.addView(mSurfaceView);
mLayout.addView(mVideo);
mFrameLayout.addView(mLayout);
setContentView(mFrameLayout);
// with xml
// setContentView(R.layout.main);
// mFrameLayout = (FrameLayout) findViewById(R.id.activity_reader);
// mLayout = (RelativeLayout) findViewById(R.id.videoview);
// mVideo = (VideoView) findViewById(R.id.video_view);
// mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
// Set the handler to me messaged from the threads
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg != null) {
mVideo.setMediaController(new MediaController(mVideo.getContext()));
mVideo.setVideoPath("/mnt/sdcard/myvideo.mp4");
if (mLayout.getVisibility() == View.VISIBLE) {
mLayout.setVisibility(View.GONE);
} else {
mLayout.setVisibility(View.VISIBLE);
}
// mFrameLayout.bringChildToFront(mLayout);
// mFrameLayout.bringChildToFront(mVideo);
// mFrameLayout.requestLayout();
// mFrameLayout.invalidate();
// mFrameLayout.postInvalidate();
// mVideo.requestFocus();
}
super.handleMessage(msg);
}
};
}
/** Inflate the menu */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_reader_menu, menu);
return true;
}
/** Handle menu items events */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.toggle_video:
new Thread() {
public void run() {
mHandler.sendEmptyMessage(0);
};
}.start();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_reader"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView android:id="@+id/surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone">
<VideoView android:id="@+id/video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</FrameLayout>
一个提示:因为这只是一个找出它为什么不起作用的测试,所以我尝试最小化我的真实应用程序中的代码,其中 VideoView
的可见性由处理程序控制从 SurfaceView
的绘图线程获取消息。这就是为什么我实现了一个在使用菜单时发送消息的线程。
最佳答案
根据 this thread,我不认为你可以有重叠的 SurfaceViews Android框架工程师回答:
Sorry, you can't do this -- because surface views are very special and not really views (the surface is a separate window Z-ordered with your own), their Z-ordering does not match your views. A surface view is a big, heavy object; you are not intended to treat SurfaceView like a regular view in this way.
关于android - SurfaceView 之上的 VideoView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5433525/
这是我的代码 fragment ,我想在其中播放来自服务器的视频 private void PlayVideo() { try { getWindow().setFormat(
我对 Android Studio 相当陌生,正在尝试一个项目,其中基于点击事件,videoView(2 个视频)从 vid1 变为 vid2,vid2 变为 vid1 等等,并且两者同时播放且长度相
我感兴趣的是能够在 VideoView B 播放时“预缓冲”VideoView A。这可能吗? 我有两个 VideoView 实例。 在给定时间只会显示一个 VideoView,占据手机的整个屏幕。
我最初隐藏了 VideoView,当加载视频时,我正在显示 VideoView。但是,如果 VideoView 最初是 invisible,则永远不会调用 onPrepared。但是,如果 Video
我正在尝试将视频添加到我的应用程序中。视频本地存储在 res/raw 中。我不知道为什么会出现“videoView.setVideoURI("uri");”错误和“videoView.start();
我正在创建一个应用程序来在 Amazon FireTV 机顶盒上播放各种类型的视频。如果我使用默认的 Android VideoView 播放视频。如果我使用 Vitamio 的 VideoView,
我必须在 android 上强制使用 videoView.setZOrderOnTop(true)。但是在使用它之后,我无法在 videoView 上显示按钮。即使在设置 videoView.setZ
我正在尝试制作一个带有 VideoView 的视频播放器,它支持在其上使用 TextView 的字幕。 我已经解析了字幕,但现在我需要一个在每次帧更改时运行的事件,以使用当前播放位置更新字幕。 我尝试
我有一个 *.mp4文件,持续时间为 2 分钟。现在它有从 30 seconds upto 1.10 min 开始的音轨. 30s 之前的其余部分及之后 1.10min为空白。 现在的问题是当我尝试在
我想在我的started_activity背景下运行视频 View 。但加载失败。 屏幕是黑色的,如果我导航或将我的页面推送到另一个页面两次,它将显示应用程序没有响应警报。 我遵循这个视频教程:htt
我在这里使用imageView,当我点击它时应该向我显示一个视频(线性10),这个视频大约4秒,我需要一个代码,当我再次点击imageView 视频应该再次开始播放,每次我单击 imageView 时
我的一个 Activity 中有一个 VideoView,如果我尝试按后退 Button,它不会将我带到之前的 Activity 并且它也不会在日志猫中给出任何错误消息。 我尝试覆盖 onBackPr
我正在制作一个视频播放器,它将从服务器流式传输视频。我已经检查过,视频网址正确且有效!已经很晚了,所以我可能错过了一些东西,但为什么会这样 VideoView videoView = (VideoVi
我有一个应用程序正在从另一个充当服务器的应用程序接收视频文件。当应用程序保存在套接字上接收到的文件时,视频流开始播放该文件(正在构建中)。在代码示例中,按下 btnStream 后,按下 btnPla
我有一个视频 View ,我希望能够播放/暂停和全屏显示。我无法让视频显示控件。 private fun showVideo() { isLottieVisible = false
我制作了一个应用程序,我想在其中播放原始文件夹中的 SWF 文件。 当我运行应用程序时,它会显示 Sorry, the video cant be played. 我不知道如何纠正它。我已经在设备上安
有谁知道为什么我的应用程序在打印出 VideoView 中的变量时只返回错误的值? @Override public void onCreate(Bundle savedInstanceState)
我想编写在单击按钮时播放视频的代码。我无法显示视频。当我点击按钮播放时,模拟器停止工作。 public class Video extends Activity{ private static fin
所以我正在尝试在 android 中播放基本的 avi 视频,它似乎在 Windows Media Player、VLC 等上运行良好,所以它看起来不需要任何复杂的编解码器。我的应用程序中有一个视频
我正在开发具有两个 View 的应用程序,一个是 UI,另一个是 VideoView。在某些事件发生之前使用 UI 线程,然后我想将 setContentView 设置为 VideoView,但是在将
我是一名优秀的程序员,十分优秀!