2016-03-23 75 views
0

我試圖播放ListView中的文件,其中mediaPlayer類。java.io.IOException:準備失敗:狀態= 0x1在Android中

像這樣:

public void initializeViews() { 
    Intent intent = getIntent(); 
    String fName = intent.getStringExtra("fileName"); 
    fileName = (TextView) findViewById(R.id.fileName); 
    duration = (TextView) findViewById(R.id.songDuration); 
    seekbar = (SeekBar) findViewById(R.id.seekBar); 
    playBtn = (ImageButton) findViewById(R.id.media_play); 
    try { 
     mediaPlayer = new android.media.MediaPlayer(); 
     mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     mediaPlayer.setDataSource(fName); 
     mediaPlayer.prepare(); 
    } 
    catch (IOException e) { 
     e.printStackTrace(); 
    } 
    fileName.setText(fName.substring(fName.lastIndexOf("/") + 1)); 
    finalTime = mediaPlayer.getDuration(); 
    seekbar.setOnSeekBarChangeListener(mOnSeek); 
    seekbar.setMax((int) finalTime); 
    seekbar.setClickable(true); 
    mediaPlayer.start(); 
    timeElapsed = mediaPlayer.getCurrentPosition(); 
    seekbar.setProgress((int) timeElapsed); 
    durationHandler.postDelayed(updateSeekBarTime, 200); 
} 

我在互聯網上搜索,而最的問題是檢查文件的路徑,但fName得到了完整路徑的文件。但我不知道它顯示例外:

java.io.IOException: Prepare failed.: status=0x1

的所有日誌應用程序時出現異常:

E/MediaPlayer: error (1, -2147483648) 
W/System.err: java.io.IOException: Prepare failed.: status=0x1 
W/System.err:  at android.media.MediaPlayer.prepare(Native Method) 
W/System.err:  at kr.co.composer.callrecord.media.AudioPlayer.initializeViews(AudioPlayer.java:56) 
W/System.err:  at kr.co.composer.callrecord.media.AudioPlayer.onCreate(AudioPlayer.java:42) 
W/System.err:  at android.app.Activity.performCreate(Activity.java:5231) 
W/System.err:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
W/System.err:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
W/System.err:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
W/System.err:  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
W/System.err:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:102) 
W/System.err:  at android.os.Looper.loop(Looper.java:136) 
W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:5001) 
W/System.err:  at java.lang.reflect.Method.invokeNative(Native Method) 
W/System.err:  at java.lang.reflect.Method.invoke(Method.java:515) 
W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
W/System.err:  at dalvik.system.NativeStart.main(Native Method) 
E/MediaPlayer: Attempt to call getDuration without a valid mediaplayer 
E/MediaPlayer: error (-38, 0) 
E/MediaPlayer: start called in state 0 
E/MediaPlayer: error (-38, 0) 
E/MediaPlayer: Error (-38,0) 
E/MediaPlayer: Error (-38,0) 
W/EGL_genymotion: eglSurfaceAttrib not implemented 
stop called in state 0 
error (-38, 0) 
stop called in state 0 
error (-38, 0) 
Error (-38,0) 
Error (-38,0) 
stop called in state 0 
error (-38, 0) 
Error (-38,0) 
pause called in state 0 
error (-38, 0) 
+0

您可以添加更多日誌嗎? –

+0

@ TungD.Nguyen我更新了我的日誌。 –

回答

0

可能造成的閱讀權限。通過在manifest文件中插入權限進行修復:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
+0

我添加了權限。但是這個錯誤繼續出現。 –

相關問題