0

我有此流如何從互聯網android播放videostreaming?

http://www.tvrey.com/canal_5.html 

我試圖用兩種方式

但始終我

無法播放這部影片。

import android.media.MediaPlayer; 
import android.media.MediaPlayer.OnPreparedListener; 
import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.app.ProgressDialog; 
import android.util.Log; 
import android.widget.MediaController; 
import android.widget.VideoView; 

public class VideoViewActivity extends Activity { 

    // Declare variables 
    ProgressDialog pDialog; 
    VideoView videoview; 

    // Insert your Video URL 
    String VideoURL = "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // Get the layout from video_main.xml 
     setContentView(R.layout.videoview_main); 
     // Find your VideoView in your video_main.xml layout 
     videoview = (VideoView) findViewById(R.id.VideoView); 
     // Execute StreamVideo AsyncTask 

     // Create a progressbar 
     pDialog = new ProgressDialog(VideoViewActivity.this); 
     // Set progressbar title 
     pDialog.setTitle("Android Video Streaming Tutorial"); 
     // Set progressbar message 
     pDialog.setMessage("Buffering..."); 
     pDialog.setIndeterminate(false); 
     pDialog.setCancelable(false); 
     // Show progressbar 
     pDialog.show(); 

     try { 
      // Start the MediaController 
      MediaController mediacontroller = new MediaController(
        VideoViewActivity.this); 
      mediacontroller.setAnchorView(videoview); 
      // Get the URL from String VideoURL 
      Uri video = Uri.parse(VideoURL); 
      videoview.setMediaController(mediacontroller); 
      videoview.setVideoURI(video); 

     } catch (Exception e) { 
      Log.e("Error", e.getMessage()); 
      e.printStackTrace(); 
     } 

     videoview.requestFocus(); 
     videoview.setOnPreparedListener(new OnPreparedListener() { 
      // Close the progress bar and play the video 
      public void onPrepared(MediaPlayer mp) { 
       pDialog.dismiss(); 
       videoview.start(); 
      } 
     }); 

    } 

} 

,這是從這個鏈接

http://code.tutsplus.com/tutorials/streaming-video-in-android-apps--cms-19888 

複製的其他方式,但我得到同樣的結果。

回答

0

嘗試註冊setOnErrorListener(MediaPlayer.OnErrorListener l)以檢查在準備或回放過程中是否發生錯誤。

+0

@angel請在實現OnErrorListener後分享您的錯誤代碼,以便更容易排除故障。 –