ONBOOT完成的媒体播放器无法正常工作

时间:2018-06-03 07:19:12

标签: android android-mediaplayer

通常媒体播放器工作正常,但是当我重新启动设备时,媒体播放器工作不正常。 ONBOOT完成我必须开始录音,第一次录音机启动,当我试图停止它时,它不会停止并收到错误,录制的文件被破坏,当我尝试播放它,然后我得到这个错误< / p>

  

“无法播放您要求的曲目”       E / MediaRecorder:开始失败:-38       06-03 11:54:46.883 11025-11025 / com.aykuttasil.callrecorder W / System.err:java.lang.IllegalStateException       06-03 11:54:46.883 11025-11025 / com.aykuttasil.callrecorder W / System.err:at android.media.MediaRecorder._start(Native Method)       06-03 11:54:46.883 11025-11025 / com.aykuttasil.callrecorder W / System.err:at   android.media.MediaRecorder.start(MediaRecorder.java:946)               在com.aykuttasil.callrecord.receiver.CallRecordReceiver.startRecord(CallRecordReceiver.java:104)               在com.aykuttasil.callrecord.receiver.CallRecordReceiver.onOutgoingCallStarted(CallRecordReceiver.java:58)               在com.aykuttasil.callrecord.receiver.PhoneCallReceiver.onCallStateChanged(PhoneCallReceiver.java:124)               在com.aykuttasil.callrecord.receiver.PhoneCallReceiver.onReceive(PhoneCallReceiver.java:83)               在android.app.LoadedApk $ ReceiverDispatcher $ Args.run(LoadedApk.java:993)

我已在清单中注册了广播。

 <receiver android:name=".receiver.CallRecordReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>

        </receiver>
 private void startRecord(Context context, String seed, String phoneNumber) {
        try {
            boolean isSaveFile = PrefsHelper.readPrefBool(context, CallRecord.PREF_SAVE_FILE);
            Log.i(TAG, "isSaveFile: " + isSaveFile);

            // dosya kayıt edilsin mi?
            if (!isSaveFile) {
                return;
            }

            if (isRecordStarted) {
                try {
                    recorder.stop();  // stop the recording
                } catch (RuntimeException e) {
                    // RuntimeException is thrown when stop() is called immediately after start().
                    // In this case the output file is not properly constructed ans should be deleted.
                    Log.d(TAG, "RuntimeException: stop() is called immediately after start()");
                    //noinspection ResultOfMethodCallIgnored
                    audiofile.delete();
                }
                releaseMediaRecorder();
                isRecordStarted = false;
            } else {
                if (prepareAudioRecorder(context, seed, phoneNumber)) {
                    recorder.start();
                    isRecordStarted = true;
                    onRecordingStarted(context, callRecord, audiofile);
                    Log.i(TAG, "record start");
                } else {
                    releaseMediaRecorder();
                }
                //new MediaPrepareTask().execute(null, null, null);
            }
        } catch (IllegalStateException e) {
            e.printStackTrace();
            releaseMediaRecorder();
        } catch (RuntimeException e) {
            e.printStackTrace();
            releaseMediaRecorder();
        } catch (Exception e) {
            e.printStackTrace();
            releaseMediaRecorder();
        }
    }

    private void stopRecord(Context context) {
        try {
            if (recorder != null && isRecordStarted) {
                releaseMediaRecorder();
                isRecordStarted = false;
                onRecordingFinished(context, callRecord, audiofile);
                Log.i(TAG, "record stop");
            }
        } catch (Exception e) {
            releaseMediaRecorder();
            e.printStackTrace();
        }
    }

0 个答案:

没有答案