- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一个简单的 VideoView 来播放文件系统中的视频。视频加载和播放都很好。但是,我想知道视频何时结束播放,以便我可以完成() Activity 并继续下一个 Activity 。这是我的。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/videoPlayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true"
android:orientation="vertical" >
<VideoView
android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Activity 如下。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.videoplayer);
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
Intent result = new Intent();
setResult(1, result);
finish();
}
}); // video finish listener
Intent intent = getIntent();
// Receiving the Data
String fileName = intent.getStringExtra("fileName");
videoView.setVideoPath(fileName);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();}
我从另一个 Activity 中调用此 Activity 。这是 Activity 定义。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:keepScreenOn="true">
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/imageViewDescription" />
</LinearLayout>
VideoPlayer Activity 类
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.imageplayer);
imageView = (ImageView) findViewById(R.id.imageView);
updateUI(new File("/sdcard/Test/Test.3gp");
}
public void updateUI(File file)
{
if (file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".png"))
{
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
}
else if (file.getName().toLowerCase().endsWith(".3gp") || file.getName().toLowerCase().endsWith(".mp4"))
{
//Starting a new Intent
Intent nextScreen = new Intent(getApplicationContext(), VideoPlayer.class);
//Sending data to another Activity
nextScreen.putExtra("fileName", file.getAbsolutePath());
released = false;
startActivityForResult(nextScreen, resultCode);
}
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
}
永远不会调用 onCompletion 方法,也不会调用此 Activity 调用者中的 onActivityResult() 方法。我想知道这有什么问题。我尝试同时播放“.3gp”和“.mp4”文件,结果相同。请帮忙
最佳答案
在 onPreparedListener 中调用 videoView.start() 并使用 false 值设置 mediaplayer 对象循环。我希望这会奏效..喜欢如下:
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(false); //make sure to use this statement
video.start();
Toast.makeText(mContext,String.valueOf(vtime),Toast.LENGTH_LONG).show();
}
});
关于Android VideoView OnCompletionListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8978708/
这是我的代码 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,但是在将
我是一名优秀的程序员,十分优秀!