Android: Is There a way to stream video on a app?

后端 未结 1 1680
花落未央
花落未央 2020-12-29 17:36

I\'ve seen apps like netflix that stream video. Is there a way to do this using the sdk? I could not find anything about how to stream on android.

相关标签:
1条回答
  • 2020-12-29 17:38

    Here a simple example of a VideoView streaming a file

    public class VideoPlayer extends Activity {
    
    String url = "http://yourvideo/url/video.mp4";
    
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
           VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
           myVideoView.setVideoURI(Uri.parse(url));
           myVideoView.setMediaController(new MediaController(this));
           myVideoView.requestFocus();
           myVideoView.start();
       }
    }
    

    And in your XML somewhere:

    <VideoView
       android:id="@+id/myvideoview"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content" />
    
    0 讨论(0)
提交回复
热议问题