从Android MediaPlayer中的原始文件夹播放视频时出错

时间:2015-04-19 10:19:46

标签: android android-mediaplayer media

我正在尝试从原始文件夹播放视频,但导致它返回以下错误

  

错误(1,-2147483648)

这是我的代码:

public class AndroidVideoPlayer extends Activity implements SurfaceHolder.Callback{

    MediaPlayer mediaPlayer;
    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    boolean pausing = false;;
    Button btn1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        setContentView(R.layout.main); 
            Button buttonPlayVideo = (Button)findViewById(R.id.button1);

            getWindow().setFormat(PixelFormat.UNKNOWN);

            //Displays a video file.   
            VideoView mVideoView = (VideoView)findViewById(R.id.videoview);

            String uriPath = "android.resource://com.AndroidVideoPlayer/raw/"+R.raw.k;

            Uri uri = Uri.parse(uriPath);
            mVideoView.setVideoURI(uri);
            mVideoView.requestFocus();
            mVideoView.start();



            buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View v) {

                    // VideoView refference see main.xml
                    VideoView mVideoView = (VideoView)findViewById(R.id.videoview);

                    String uriPath = "android.resource://com.AndroidVideoPlayer/"+R.raw.k;

                    Uri uri = Uri.parse(uriPath);
                    mVideoView.setVideoURI(uri);
                    mVideoView.requestFocus();
                    mVideoView.start();


            }});
     }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub

    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub

    }
}

1 个答案:

答案 0 :(得分:0)

注意:已知MediaPlayers是有问题的,因为它们是在@ API 1中创建的。因此建议您手动处理媒体播放器的所有错误。

您的问题: 简而言之,您没有将媒体播放器与表面连接

你可以快速尝试:

$dataProvider = new ActiveDataProvider([
    'query' => Record::find()->joinWith(['recordUsers'])->where(['user_id'=> Yii::$app->user->identity->id]),
]);

我建议您尝试使用以下VideoPlayerManager类。

用法示例

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    mediaPlayer.setDisplay(holder);

}

VideoPlayerManager类

VideoView videoView = ((VideoView) findViewById(R.id.VideoView));
_videoPlayer = new VideoPlayerManager(getApplicationContext(),videoView);
videoView.getHolder().addCallback(_videoPlayer);