Я пытаюсь реализовать простой VideoView, который будет воспроизводить видео из файловой системы. Видео загружается отлично и играет отлично. Тем не менее, я хотел бы знать, когда видео закончил игру, чтобы я смог закончить() действие и возобновить со следующего. Вот что у меня есть.Android VideoView OnCompletionListener не работает
<?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>
Деятельность такова, как показано ниже.
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();}
Я называю это мероприятие из другой деятельности. Вот определение активности.
<?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 активность Класс
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 никогда не вызывается и метод onActivityResult() в вызывающем этой деятельности также не называется. Я хотел бы знать, что с этим не так. Я попытался воспроизвести файлы «.3gp» и «.mp4» с тем же результатом. Пожалуйста, помогите