MediaPlayerNative:调用失败:错误状态1,mPlayer(0x0)

时间:2018-03-20 19:39:29

标签: android android-mediaplayer file-descriptor

我很难调试这些东西。顺便说一句,我的设置是使用FileDescriptor数据播放视频内容,记录和发送数据到连接设备是相当不错的。但是当我尝试读取数据时,初始化MediaPlayer会给我带来错误。

03-21 03:33:02.111 27481-27481/shaveyourneck.syn.app.com.shaveyourneck E/CameraActivity: onPayloadReceived: STREAM DATA RECIEVED!  -------> I recieve the FileDescriptor data
03-21 03:33:02.131 27481-27481/shaveyourneck.syn.app.com.shaveyourneck E/CameraActivity: onPayloadTransferUpdate: STco  com.google.android.gms.nearby.connection.PayloadTransferUpdate@f7a66429
03-21 03:33:02.131 27481-27481/shaveyourneck.syn.app.com.shaveyourneck E/CameraActivity: onPayloadTransferUpdate: STREAM PAYLOAD
03-21 03:33:02.134 27481-27481/shaveyourneck.syn.app.com.shaveyourneck E/MediaPlayerNative: invoke failed: wrong state 1, mPlayer(0x0) ---------> Error i encounter when i initialize MediaPlayer and START PLAYING the content
03-21 03:33:02.139 1755-9892/? E/HsmCoreServiceImpl: onTransact in code is: 102
03-21 03:33:02.141 27481-27481/shaveyourneck.syn.app.com.shaveyourneck E/StreamMediaPlayer: run: fileDescriptor stuffs Exception failure code: -38
                                                                                        failure code: -38 --------> ERROR CODE i recieved

这是我的媒体播放器来源

{

    activity = act;
    fileDescriptor = fileDescriptorVal;
    fileInputStream = new FileInputStream(fileDescriptorVal);

    r = new Runnable() {
        @Override
        public void run() {

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    if (mediaPlayer == null) {
                        Log.e(TAG, "startVideo: MEDIA PLAYER NULL,creating new instance");
                        mediaPlayer = new MediaPlayer();
                    }


                    if (!fileDescriptor.valid()) {
                        Log.e(TAG, "run: FILE DESCRIPTOR NOT VALID  ?????");
                        try {
                            fileDescriptor.sync();
                        } catch (SyncFailedException e) {
                            Log.e(TAG, "run: CANY SYNC");
                            e.printStackTrace();
                        }
                    }
                    try {
                        mediaPlayer.setWakeMode(activity, PowerManager.PARTIAL_WAKE_LOCK);
                        mediaPlayer.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
                        mediaPlayer.setDataSource(fileInputStream.getFD());
                        mediaPlayer.prepareAsync();
                        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                            @Override
                            public void onPrepared(MediaPlayer mediaPlayer1) {
                                Log.e(TAG, "onPrepared: STARTING VIDEO!");
                                mediaPlayer1.start();
                            }
                        });
                        mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                            @Override
                            public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
                                return false;
                            }
                        });

                    } catch (IOException e) {
                        e.printStackTrace();
                        mediaPlayer.release();
                        mediaPlayer = null;
                        Log.e(TAG, "run: fileDescriptor stuffs IOException " + e.getMessage() + "\n" + e.getLocalizedMessage());
                    } catch (Exception ex) {
                        mediaPlayer.release();
                        mediaPlayer = null;
                        Log.e(TAG, "run: fileDescriptor stuffs Exception " + ex.getMessage() + "\n" + ex.getLocalizedMessage()); -----> ERROR DETECTS HERE
                    }


                }
            });

        }
    };

    handler.post(r);

}

0 个答案:

没有答案