0

Androidアプリ開発初心者です。私は 1 つのビデオ プレーヤーを開発したいと考えています。このビデオ プレーヤーでは、再生するビデオを選択するためにビデオ ファイルを開くためのファイル チューザー/ファイル エクスプローラーを実装する必要があります。これですべて正常に動作しています。

ビデオ以外のファイルを再生しようとすると、次のようなエラー メッセージが表示されることはわかっています。

Sorry,this video cannot be play

これも正常に動作しています。問題は次のとおりです。

  1. このエラー メッセージ (申し訳ありませんが、このビデオは再生できません) が 2 回表示されるのはなぜですか?
  2. エラー メッセージが表示された後、ファイル チューザーから新しいファイルを開こうとすると、そのエラー メッセージが再度表示されます。(つまり) 新しい正しいビデオ ファイルを選択した後、選択したビデオ ファイルを再生する前に、このエラー メッセージが突然 (再度呼び出されて) 表示されます。

これは私のコードです:

package com.example.video_bug;

import java.io.File;

import com.ipaulpro.afilechooser.utils.FileUtils;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

public class MainActivity extends Activity {

    VideoView player;
    Button b1,b2,b3;
    String videoFilePath;
     private static final int REQUEST_CODE = 6384;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        player = (VideoView) findViewById(R.id.videoView1);
        b1=(Button)findViewById(R.id.button1);
        b2=(Button)findViewById(R.id.button2);
        b3=(Button)findViewById(R.id.button3);

        b1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                showChooser();
            }
        });

        b2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                player.setVideoURI(Uri.parse(videoFilePath));
                  player.setMediaController(new   MediaController(MainActivity.this));
                   player.requestFocus();
                player.start();
            }
        });

      b3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            player.stopPlayback();
        }
    });

}

    private void showChooser() {
        // Use the GET_CONTENT intent from the utility class
        Intent target = FileUtils.createGetContentIntent();
        // Create the chooser Intent
        Intent intent = Intent.createChooser(
                target, getString(R.string.chooser_title));
        try {
            startActivityForResult(intent, REQUEST_CODE);
        } catch (ActivityNotFoundException e) {
            // The reason for the existence of aFileChooser
        }               
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case REQUEST_CODE:  
            // If the file selection was successful
            if (resultCode == RESULT_OK) {      
                if (data != null) {
                    // Get the URI of the selected file
                    final Uri uri = data.getData();

                    try {
                        // Create a file instance from the URI
                        final File file = FileUtils.getFile(uri);
                        videoFilePath=file.getAbsolutePath();
                        Toast.makeText(MainActivity.this, 
                                "File Selected: "+file.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    } catch (Exception e) {
                        Log.e("FileSelectorTestActivity", "File select error", e);
                    }
                }
            } 
            break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        Log.e("called","onPause");
        super.onPause();
    }


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        Log.e("called","onResume");
        super.onResume();
    }

}

このエラーを解決するにはどうすればよいですか? 誰でも私がしたことのエラーを見つけるのを手伝ってくれます

4

0 に答える 0