视频流和Android视频、Android

2023-09-12 03:56:01 作者:不爱又何必纠缠

今天我的应用程序(的Andr​​oid 2.1)中的一个,我想从URL流式播放视频。

Today for one of my app (Android 2.1), I wanted to stream a video from an URL.

据我探索的Andr​​oid SDK这是相当不错的,我喜欢的几乎的每一块。 但现在,它涉及到视频流那种我很失落。

As far as I explored Android SDK it's quite good and I loved almost every piece of it. But now that it comes to video stream I am kind of lost.

有关您需要了解Android SDK中的任何信息,你有成千上万的博客告诉你如何做到这一点。当涉及到视频流媒体,它的不同。信息是丰富的。

For any information you need about Android SDK you have thousands of blogs telling you how to do it. When it comes to video streaming, it's different. Informations is that abundant.

每个人都做了它的方式欺骗​​在这里和那里。

Everyone did it it's way tricking here and there.

有没有良好的了解过程,允许一个流式播放视频?

Is there any well-know procedure that allows one to stream a video?

难道谷歌认为使它更容易为它的开发呢?

Did google think of making it easier for its developers?

推荐答案

如果你想只使用默认的播放器的操作系统播放视频,你会使用这样的意图:

If you want to just have the OS play a video using the default player you would use an intent like this:

String videoUrl = "insert url to video here";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(videoUrl));
startActivity(i);

不过,如果你想创建一个视图自己和流媒体视频吧,一个方法是建立在你的布局videoview,并使用媒体播放器的视频流吧。下面是在XML中videoview:

However if you want to create a view yourself and stream video to it, one approach is to create a videoview in your layout and use the mediaplayer to stream video to it. Here's the videoview in xml:

<VideoView android:id="@+id/your_video_view"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
/>

然后在的onCreate在你的活动你会发现视图并启动媒体播放器。

Then in onCreate in your activity you find the view and start the media player.

    VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
    MediaController mc = new MediaController(this);
    videoView.setMediaController(mc);

    String str = "the url to your video";
    Uri uri = Uri.parse(str);

    videoView.setVideoURI(uri);

    videoView.requestFocus();
    videoView.start();

退房videoview监听器被通知当视频完成播放或出现错误时(VideoView.setOnCompletionListener,VideoView.setOnErrorListener等)。

Check out the videoview listeners for being notified when the video is done playing or an error occurs (VideoView.setOnCompletionListener, VideoView.setOnErrorListener, etc).

 
精彩推荐