使用记录的文件.3gp时,MediaPlayer准备失败错误(1,-17)

使用记录的文件.3gp时,MediaPlayer准备失败错误(1,-17),第1张

概述我正在尝试从AudioRecorder录制,然后尝试与MediaPlayer播放相同的文件,但是它给mediaplayer.prepare()的准备失败.任何人都可以告诉我什么合适的理由.下面是我正在使用的代码publicvoidonClick(Viewv){recorder=newMediaRecorder();

我正在尝试从AudioRecorder录制,然后尝试与Media Player播放相同的文件,但是它给mediaplayer.prepare()的准备失败.任何人都可以告诉我什么合适的理由.
下面是我正在使用的代码

        public voID onClick(VIEw v) {            recorder = new MediaRecorder();            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);            recorder.setoutputFormat(MediaRecorder.OutputFormat.THREE_GPP);            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);            if(case_value==0)                recorder.setoutputfile(deviceMIC_path);            else if(case_value==1)                recorder.setoutputfile(deviceMIC_Handset_path);            else if(case_value==2)                recorder.setoutputfile(headsetMIC_path);            recorder.setonErrorListener(errorListener);            recorder.setonInfoListener(infoListener);            try {                recorder.prepare();                recorder.start();                if (ENABLE_LOGS)                    Log.e(LOG_TAG, resources                            .getString(R.string.record_started));                Toast.makeText(context,                        resources.getString(R.string.record_started),                        Toast.LENGTH_LONG).show();                recording = true;            } catch (IllegalStateException e) {                Log.e("","ILLEAgal EXCEPTION...");e.printstacktrace();            } catch (IOException e) {                e.printstacktrace();                Log.e("","IO EXCEPTION...");            }            catch(Exception e){                e.printstacktrace();                Log.e("","UNKNowN EXCEPTION...");            }        }    });    stopbutton.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            if (recording) {                if (ENABLE_LOGS)                    Log.e(LOG_TAG, "Record is going to be stoped...");                recorder.stop();                if (ENABLE_LOGS)                    Log.e(LOG_TAG, "Record StopPED....");                Toast                        .makeText(context, "Record StopPED",                                Toast.LENGTH_LONG).show();                recorder.release();                recorder=null;            }        }    });    playbutton.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            MediaPlayer mediaplayer = new MediaPlayer();            try {                if(case_value==0)                        mediaplayer.setDataSource(deviceMIC_path);                else if(case_value==1)                    mediaplayer.setDataSource(deviceMIC_Handset_path);                else if(case_value==2)                    mediaplayer.setDataSource(headsetMIC_path);            } catch (IllegalArgumentException e) {                e.printstacktrace();            } catch (IllegalStateException e) {                e.printstacktrace();            } catch (IOException e) {                e.printstacktrace();            }            try {                mediaplayer.prepare();            } catch (IllegalStateException e) {                e.printstacktrace();            } catch (IOException e) {                e.printstacktrace();            }            catch(Exception e){                e.printstacktrace();            }            // mAudioManager.setSpeakerphoneOn(false);            if (ENABLE_LOGS)                Log.e(LOG_TAG, "CASE VALUE : " + case_value);            if (case_value == 0) {                if (MainActivity.headsetState == 0) {                    if (!mediaplayer.isPlaying()) {                        mediaplayer.start();                        if (ENABLE_LOGS)                            Log.e(LOG_TAG, "PLAY started...");                        Toast.makeText(context, "PLAY started...",                                Toast.LENGTH_LONG).show();                    } else {                        mediaplayer.stop();                    }

以下是我遇到的错误

12-12 12:00:01.186: E/com.brcm.factorymode.audioloop.AudioLoopFtmTestActivity(1860): Record started12-12 12:00:04.467: E/com.brcm.factorymode.audioloop.AudioLoopFtmTestActivity(1860): Record is going to be stoped...12-12 12:00:04.592: E/com.brcm.factorymode.audioloop.AudioLoopFtmTestActivity(1860): Record StopPED....12-12 12:00:06.710: W/MediaPlayer(1860): info/warning (1, 26)12-12 12:00:06.725: E/MediaPlayer(1860): error (1, -17)12-12 12:00:06.725: W/System.err(1860): java.io.IOException: Prepare Failed.: status=0x112-12 12:00:06.725: W/System.err(1860):     at androID.media.MediaPlayer.prepare(Native Method)12-12 12:00:06.725: W/System.err(1860):     at com.brcm.factorymode.audioloop.AudioLoopFtmTestActivity.onClick(AudioLoopFtmTestActivity.java:155)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEw.performClick(VIEw.java:2364)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEw.ontouchEvent(VIEw.java:4179)12-12 12:00:06.725: W/System.err(1860):     at androID.Widget.TextVIEw.ontouchEvent(TextVIEw.java:6534)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEw.dispatchtouchEvent(VIEw.java:3709)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:883)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:883)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:883)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:883)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:883)12-12 12:00:06.725: W/System.err(1860):     at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.superdispatchtouchEvent(PhoneWindow.java:1659)12-12 12:00:06.725: W/System.err(1860):     at com.androID.internal.policy.impl.PhoneWindow.superdispatchtouchEvent(PhoneWindow.java:1107)12-12 12:00:06.725: W/System.err(1860):     at androID.app.Activity.dispatchtouchEvent(Activity.java:2061)12-12 12:00:06.725: W/System.err(1860):     at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.dispatchtouchEvent(PhoneWindow.java:1643)12-12 12:00:06.725: W/System.err(1860):     at androID.vIEw.VIEwRoot.handleMessage(VIEwRoot.java:1691)12-12 12:00:06.725: W/System.err(1860):     at androID.os.Handler.dispatchMessage(Handler.java:99)12-12 12:00:06.725: W/System.err(1860):     at androID.os.Looper.loop(Looper.java:123)12-12 12:00:06.733: W/System.err(1860):     at androID.app.ActivityThread.main(ActivityThread.java:4338)12-12 12:00:06.741: W/System.err(1860):     at java.lang.reflect.Method.invokeNative(Native Method)12-12 12:00:06.741: W/System.err(1860):     at java.lang.reflect.Method.invoke(Method.java:521)12-12 12:00:06.741: W/System.err(1860):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)12-12 12:00:06.741: W/System.err(1860):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:618)12-12 12:00:06.741: W/System.err(1860):     at dalvik.system.NativeStart.main(Native Method)12-12 12:00:06.741: E/com.brcm.factorymode.audioloop.AudioLoopFtmTestActivity(1860): CASE VALUE : 012-12 12:00:06.749: E/MediaPlayer(1860): start called in state 012-12 12:00:06.749: E/MediaPlayer(1860): error (-38, 0)12-12 12:00:06.749: E/com.brcm.factorymode.audioloop.AudioLoopFtmTestActivity(1860): PLAY started...12-12 12:00:06.756: I/MediaPlayer(1860): Info (1,26)12-12 12:00:06.756: E/MediaPlayer(1860): Error (-38,0)

任何人都可以告诉我解决此问题的方法.

解决方法:

实现OnCompletionListener并将其注册到MediaPlayer实例.

播放完媒体后,它将在onCompletion上调用此回调方法

voID onCompletion(MediaPlayer mp){   //Here you stop it.   mp.stop();   //reset the data source path to the new file   mp.setDataSource(<uri>);   mp.prepare(); // or mp.prepareAsync();   // start the mediaplayer after the prepare has completed.}

播放完所有文件后,释放mediaplayer实例.

总结

以上是内存溢出为你收集整理的使用记录的文件.3gp时,MediaPlayer准备失败错误(1,-17)全部内容,希望文章能够帮你解决使用记录的文件.3gp时,MediaPlayer准备失败错误(1,-17)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1092886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存