0

在我的应用程序中,我正在尝试播放媒体播放器和搜索栏。当我尝试从存储在我的应用程序中的文件夹中播放歌曲时,它工作正常并且搜索栏被移动。

当我尝试从 SD 卡播放连续歌曲时,它会崩溃,并且在 logcat 中它显示以下错误。

ERROR/sdcard play(2500): 02 - bird flu.mp3
ERROR/MediaPlayer(2500): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
ERROR/MediaPlayer(2500): error (1, -4)
ERROR/MediaPlayer(2500): Attempt to call getDuration without a valid mediaplayer
ERROR/MediaPlayer(2500): error (-38, 0)
ERROR/sdcard play(2500): 03 Un Mela Aasadhaan.mp3
ERROR/MediaPlayer(2500): setDataSource called in state 0
ERROR/MediaPlayer(2500): prepareAsync called in state 0
ERROR/MediaPlayer(2500): Attempt to call getDuration without a valid mediaplayer
ERROR/MediaPlayer(2500): error (-38, 0)

以下是我的代码

 sv = (SurfaceView)findViewById(R.id.surfaceView1);
//        mediaPlayer =MediaPlayer.create(this, R.raw.b);        
init_mediaPlayer();     


// sv.postDelayed(runnable,200);                
  seek = (SeekBar)findViewById(R.id.seekBar1);


 seek.setMax(mediaPlayer.getDuration());

System.out.println("**** MEDIA PLAYER DURATION "+ mediaPlayer.getDuration());       


play.setOnClickListener(new View.OnClickListener() 

{
public void onClick(View v) 

{

mediaPlayer.start();

myHandler.post(runn);

isPlaying = true;

}

});


pause.setOnClickListener(new View.OnClickListener() 

{   

public void onClick(View v) 

{

mediaPlayer.pause();


mediaPlayer.prepare();


}

});

seek.setProgress(mediaPlayer.getCurrentPosition());

System.out.println("**** MEDIA PLAYER CURRENT DURATION "+ mediaPlayer.getCurrentPosition());

}


private void init_mediaPlayer() 
    {

 System.gc();

final String[] proj = { MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.SIZE };

          Log.e("media",""+proj);


musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj, null, null, null);

 Log.e("media1",""+musiccursor);


 count = musiccursor.getCount();

Log.e("media2",""+count);

 if(musiccursor!=null)

{

musiccursor.moveToFirst();

MediaPlayer mediaPlayer = new  MediaPlayer();

do{

filename=musiccursor.getString(2);

Log.e("sdcard play",filename);

mediaPlayer.setDataSource(filename);

mediaPlayer.prepare();

if(mediaPlayer.getCurrentPosition()==mediaPlayer.getDuration())         
{                           
end=musiccursor.moveToNext();                       
}               
}               
while(end);         
}
4

2 回答 2

2

看看这个

http://remwebdevelopment.com/dev/a63/Playing-Audio-error-PVMFErrNotSupported-Prepare-failed-status0x1-.html

搜索有关 PVMFErrNotSupported 的更多信息

于 2011-05-13T17:13:27.230 回答
-1

以下是我的代码,我可以在其中播放带有搜索栏移动的歌曲...

//SeekBar MediaPlayer mediaPlayer; 布尔 isPlaying = false; SurfaceView sv; //媒体播放器光标 musiccursor; int music_column_index; 整数计数;字符串文件名;布尔结束=真;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
      setContentView(R.layout.start);
        sv = (SurfaceView)findViewById(R.id.surfaceView1);
    mediaPlayer =MediaPlayer.create(this, R.raw.blue);

    seekbar = (SeekBar)findViewById(R.id.seekBar1);
    seekbar.setMax(mediaPlayer.getDuration());
    System.out.println("**** MEDIA PLAYER DURATION "+ mediaPlayer.getDuration());

     Start = (Button)findViewById(R.id.widget306);
    Start.setOnClickListener(new View.OnClickListener() 
    {   
        @Override
        public void onClick(View v) 
        {
            mediaPlayer.start(); //--> Start Media Palyer
            myHandler.post(runn); //--> SeekBar Progress
            isPlaying = true;
        }
    });
    seekbar.setProgress(mediaPlayer.getCurrentPosition());  
    seekbar = (SeekBar)findViewById(R.id.seekBar1);
}
 //SeekBar thread
 private Handler myHandler = new Handler();
 final Runnable runn = new Runnable()
 {
     public void run() 
    {
        if (mediaPlayer != null) 
        {
            if (isPlaying ) 
            {
               try 
               {
                     int currentPosition = mediaPlayer.getCurrentPosition();              
                     seekbar.setProgress(currentPosition);
               }
               catch (Exception e) 
               {
                        e.printStackTrace();
               }
               sv.postDelayed(runn, 150);
            }
          }
      }
 };
于 2011-05-24T08:03:40.683 回答