在VideoView中播放来自网址的视频

时间:2017-02-10 09:56:50

标签: android video-streaming

播放视频的网址为URL。 我的xml代码

<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<VideoView
    android:id="@+id/exerciseVideo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

我的活动中播放视频的给定网址的play vidio的java代码是

public class VidioViwer extends Base {
ProgressDialog pDialog;

VideoView videoview;
String TimeLineUrl = "http://v2sgroups.in/Erp_V2s_Groups/AndroidPanel/loadVideoFile/";

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

    // Create a progressbar
    pDialog = new ProgressDialog(VidioViwer.this);
    // Set progressbar title
    pDialog.setTitle(R.string.app_name);
    // Set progressbar message
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();
    Log.e("Error", TimeLineUrl+29);

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

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

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

我尝试上面的代码,但过了一段时间“无法播放视频”屏幕apear。如何从给定的网址播放视频。

0 个答案:

没有答案