Я пытаюсь реализовать простой VideoView, который будет воспроизводить видео из файловой системы. Видео загружается нормально и воспроизводится просто отлично. Тем не менее, я хотел бы знать, когда закончится воспроизведение видео, чтобы я мог завершить () упражнение и продолжить со следующим. Вот что у меня есть.
<?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 с одинаковым результатом. Пожалуйста, помогите