ファイルシステムからビデオを再生する単純な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'の両方のファイルを再生しようとしました。助けてください