在MediaPlayer搜索中获取错误状态错误

时间:2016-03-15 08:15:15

标签: android android-mediaplayer android-videoview

我是新手是android / java世界,我正在点击列表视图播放视频(远程URL)。当应用程序进入backhround时,我试图让视频暂停,然后在用户重新打开应用程序时恢复。我已经查看了几个有关此问题的问题以及实现我所说的Attempt to perform seekTo in wrong state: mPlayer=0x0, mCurrentState=0并且视频从头开始。这是我的活动代码:

public class VideoPlayback extends Activity {
    private static final String TAG = Dashboard.class.getSimpleName();
    ProgressBar progressBar = null;
    MediaPlayer mMediaPlayer = new MediaPlayer();
    int media_length;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_playback);
        Intent intent = getIntent();
        String message = intent.getStringExtra(Dashboard.EXTRA_MESSAGE);
        String link = "http://" + message;
        final VideoView vidView = (VideoView)findViewById(R.id.myVideo);
        progressBar = (ProgressBar) findViewById(R.id.progressbar);
        //mMediaPlayer = new MediaPlayer();
        Uri vidUri = Uri.parse(link);
        Log.d(TAG, link);
        vidView.setVideoURI(vidUri);
        try {
            MediaController vidControl = new MediaController(this);
            vidControl.setAnchorView(vidView);
            vidView.setMediaController(vidControl);


        }catch (Exception e)
        {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        vidView.requestFocus();
        vidView.start();
        progressBar.setVisibility(vidView.VISIBLE);
        vidView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.start();
                mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int arg1, int arg2) {
                        // TODO Auto-generated method stub
                        Log.d(TAG, "Changed");
                        progressBar.setVisibility(vidView.GONE);
                        mp.start();
                    }
                });
            }

        });

    }

这些是覆盖功能:

@Override
protected void onPause(){
    super.onPause();
    Log.d(TAG, "Pause called");
    mMediaPlayer.pause();
    media_length = mMediaPlayer.getCurrentPosition();



}
@Override
protected void onResume(){
    super.onResume();
    Log.d(TAG, "Resume");
    mMediaPlayer.seekTo(media_length);
    mMediaPlayer.start();


}

这是来自logcat:

03-15 13:28:17.184 25886-25886/ E/MediaPlayer: error (-38, 0)
03-15 13:28:17.184 25886-25886/ E/MediaPlayer: start called in state 0
03-15 13:28:17.239 25886-25886/ D/MediaPlayer: Couldn't open file on client side, trying server side
03-15 13:28:17.247 25886-25903/ I/MediaHTTPConnection: proxyName: 0.0.0.0 0
03-15 13:28:17.265 25886-25886/ E/MediaPlayer: Error (-38,0)
03-15 13:28:20.611 25886-25886/ D/MediaPlayer: getMetadata
03-15 13:28:20.817 25886-25886/ D/Dashboard: Changed
03-15 13:28:20.818 25886-26816/ W/MediaPlayer: info/warning (3, 0)
03-15 13:28:25.077 25886-25886/ D/Dashboard: Pause called
03-15 13:28:25.077 25886-25886/ E/MediaPlayer: pause called in state 0
03-15 13:28:30.862 25886-25886/ D/Dashboard: **Resume**
03-15 13:28:30.862 25886-25886/ E/MediaPlayer: Attempt to perform seekTo in wrong state: mPlayer=0x0, mCurrentState=0
03-15 13:28:30.866 25886-25886/ E/MediaPlayer: start called in state 0

我是这项技术的新手,非常感谢所有的帮助。

0 个答案:

没有答案