视频流和 Android

发布于 2024-10-02 10:45:01 字数 287 浏览 5 评论 0原文

今天,对于我的一个应用程序 (Android 2.1),我想从 URL 流式传输视频。

就我对 Android SDK 的探索而言,它非常好,我几乎喜欢它的每一个部分。 但现在谈到视频流,我有点迷失了。

如果您需要有关 Android SDK 的任何信息,您可以通过数以千计的博客来了解如何操作。当谈到视频流时,情况有所不同。信息就是这么丰富。

每个人都这样做,到处都是欺骗。

是否有任何众所周知的程序可以让人们流式传输视频?

谷歌是否想过让其开发者变得更容易?

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯下孤影 2024-10-09 10:45:01

如果您只想让操作系统使用默认播放器播放视频,您可以使用如下意图:

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

但是,如果您想自己创建一个视图并将视频流式传输到其中,一种方法是在布局中创建一个视频视图并使用媒体播放器将视频流式传输到它。这是 xml 中的视频视图:

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

然后在 Activity 的 onCreate 中找到视图并启动媒体播放器。

    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.setOnCompletionListener、VideoView.setOnErrorListener 等)。

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);

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"
/>

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();

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文