android mediaplayer不播放php流式传输的mp3文件

时间:2016-06-20 15:20:18

标签: php android android-mediaplayer header-files

我使用php脚本来测试我的服务器上的mp3文件,它在网络上运行正常但是当我想在Android媒体播放器中使用它的url时,android媒体播放器无法播放并抛出一些错误

这是我的PHP脚本

 $dir = "jashn-files";
 $filename = $fileID . ".mp3";
 $file = $dir."/".$filename;

 $extension = "mp3";
 $mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3";

 if(file_exists($file)){
  header('Content-type: {$mime_type}');
  header('Content-length: ' . filesize($file));
  header('Content-Disposition: filename="' . $filename . '.mp3"');
  header('X-Pad: avoid browser bug');
  header('Cache-Control: no-cache');
  $file = fopen($file, 'rb');
  if ( $file !== false ) {
   while ( !feof($file) ) {
    echo fread($file, 4096);
   }
   fclose($file);
  }

这是android app中的java代码

 new Play(Extra.Sirjan+"/jashn.php?id="+id+"+&file").execute();

  mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
   @Override
   public void onBufferingUpdate(MediaPlayer mp, int percent) {
    c.setSecondaryProgress(percent);
   }
  });
  final ImageView Play = (ImageView)((Activity)context).findViewById(R.id.Play);
  Play.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    if (mediaPlayer.isPlaying()){
     mediaPlayer.pause();
     Play.setImageResource(R.drawable.splay);
    }else {
     mediaPlayer.start();
     Play.setImageResource(R.drawable.spause);
    }
   }
  });
 }

 class Play extends AsyncTask{
 String Buffer;

  @Override
  protected void onPreExecute() {
   super.onPreExecute();
   c.setEnabled(false);
  }

  public Play(String Buffer){
  this.Buffer=Buffer;
 }

 @Override
 protected Object doInBackground(Object[] params) {
  try {
   mediaPlayer.setDataSource(Buffer);
   mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
     mediaPlayer.prepare();

  }catch (IOException e){

  }
  return null;
 }

 @Override
 protected void onPostExecute(Object o) {
  super.onPostExecute(o);
  mediaPlayer.start();
  Update_SeekBAR();
  c.setEnabled(true);

这是android studio中的错误日志

06-20 19:17:17.050 11640-11654/com.kama.khajoie.sirjan118 D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= SonyD6503 Build/23.5.A.0.575 stagefright/1.2 (Linux;Android 6.0.1)
06-20 19:17:17.050 11640-11654/com.kama.khajoie.sirjan118 D/MediaHTTPConnection: filterOutInternalHeaders: key=x-wap-profile, val= http://uaprof.sonymobile.com/D6503R2331.xml
06-20 19:17:17.052 11640-12176/com.kama.khajoie.sirjan118 D/MediaHTTPConnection: proxy null port 0
06-20 19:17:17.209 11640-12189/com.kama.khajoie.sirjan118 D/MediaHTTPConnection: proxy null port 0
06-20 19:17:17.372 11640-11654/com.kama.khajoie.sirjan118 E/MediaPlayer: error (1, -2147483648)
06-20 19:17:17.377 11640-11640/com.kama.khajoie.sirjan118 E/MediaPlayer: start called in state 0
06-20 19:17:17.377 11640-11640/com.kama.khajoie.sirjan118 E/MediaPlayer: error (-38, 0)
06-20 19:17:17.383 11640-11640/com.kama.khajoie.sirjan118 E/MediaPlayer: Error (-38,0)
06-20 19:17:49.799 11640-13186/com.kama.khajoie.sirjan118 I/GMPM: Tag Manager is not found and thus will not be used
06-20 19:18:16.888 11640-11640/com.kama.khajoie.sirjan118 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@11d1653 time:28518426

0 个答案:

没有答案