如何在Android应用程序播放流媒体直播? [英] How to play live streaming in android application?

查看:483
本文介绍了如何在Android应用程序播放流媒体直播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要提出申请板球直播。 我想知道以下几件事:

  1. 从哪里可以找到的链接打板球流?
  2. 在哪种类型的联系是这些?
  3. 是否有任何的播放器播放此类型的影片?

目前,我已经实现了网页,但我在寻找其他替代方案。

下面是我的code:

 链接1 =(RelativeLayout的)findViewById(R.id.link1);
    链接2 =(RelativeLayout的)findViewById(R.id.link2);
    LINK3 =(RelativeLayout的)findViewById(R.id.link3);
    LINK4 =(RelativeLayout的)findViewById(R.id.link4);
    link5 =(RelativeLayout的)findViewById(R.id.link5);
    link6 =(RelativeLayout的)findViewById(R.id.link6);
    link7 =(RelativeLayout的)findViewById(R.id.link7);
    link1.setOnClickListener(本);
    link2.setOnClickListener(本);
    link3.setOnClickListener(本);
    link4.setOnClickListener(本);
    link5.setOnClickListener(本);
    link6.setOnClickListener(本);
    link7.setOnClickListener(本);
}

@覆盖
公共无效的onClick(视图v){
    // TODO自动生成方法存根
    开关(v.getId()){
    案例R.id.link1:
         linkFunction(http://changevssame.blogspot.com/2014/03/willow-cricket-hd-live-streaming.html);

        打破;
    案例R.id.link2:
        linkFunction(http://changevssame.blogspot.com/2014/03/foxsports-live-streaming.html);
        打破;
    案例R.id.link3:
        linkFunction(http://changevssame.blogspot.com/2014/03/sky-sports-live-streaming.html);
        打破;
    案例R.id.link4:
        linkFunction(http://changevssame.blogspot.com/2014/03/ten-sports-live-streaming.html);
        打破;
    案例R.id.link5:
        linkFunction(http://changevssame.blogspot.com/2014/03/star-cricket.html);
        打破;
    案例R.id.link6:
        linkFunction(http://changevssame.blogspot.com/2014/03/icc-t20-world-cup-2014-live-streaming.html);
        打破;
    案例R.id.link7:
        linkFunction(http://changevssame.blogspot.com/2014/03/ptv-sports.html);
        打破;

    默认:
        打破;
    }
 

解决方案

我会尽量回答你的问题,但也有你要学习,以建立一个成功的流媒体应用的许多基本原则。

  1。从哪里可以找到的链接打板球流?
 

不知道,但是这不是一个标准的SO问题呢。

  2。哪种类型的联系是这些?
 

如果你的意思是直播流媒体链接,也有很多种类,但他们大多要么是HLS或RTSP。 HLS链接是简单的HTTP链接,往往以.m3u8定位后结束。 (如<一href="http://somewebsite.com/streams/hls_stream_video.m3u8">http://somewebsite.com/streams/hls_stream_video.m3u8")

RTSP另一方面链路,具有一个格式是这样的:的rtsp://somewebsite.com/streams/an_rtsp_stream.mp4

  3。是否有任何的播放器播放这种类型的影片?
 

当然可以。可以通过任何手段进行。 我不太确定的玩家无论你的意思是Android的API播放器或第三方播放器应用程序。所以,我将介绍这两种情况下,为您和将来的乘客。

I)的Andr​​oid API::您可以的帮助下做这样一个的MediaController ,一个的MediaPlayer SurafceView 。后两者也可被称为 VideoView 的单位实体。 有一个code在下面的答案,你可以使用。但要注意的两个关键,注意事项:

IA)使用的MediaPlayer 是很难实现,但给你比 VideoView 更详细的控制。

磅)如果你使用的是code类似于下面的答案永远不要调用prepare()对网络流。永远的 prepareAsync()。和总是呼叫 setAudioStreamType() prepareAsync之前。否则你将面临短暂的同步的对进度求时,音频和视频之间的问题。

二)播放器应用程序:我已经做了与MXPlayer流和它的伟大工程。

有一些注意事项开始前采取:

选择什么协议?

假设你的目标的Andr​​oid,我可以建议你缩小你的选择到HLS和RTSP。 你需要在做出决定之前,研究他们。但是,为了给你一个提示。 HLS是preferred较低带宽的作用时。

有许多其他的主题,比如是否要选择 UDP / TCP IP组播/广播等等...

希望以编程方式深入到编码和学习视频流?

去参观本教程。这是最完整的零到英雄导在我看来。


既然这么缺乏一个彻底的岗位上的视频流,也许我会延长我的需求的答案。

I want to make application for cricket live streaming. I want to know following things :

  1. From where I can found the links to play cricket streaming ?
  2. Which type of links are these ?
  3. Is there any player to play this type of videos ?

Currently, I have implemented web page but I am looking for other alternative.

Below is my code :

    link1 = (RelativeLayout) findViewById(R.id.link1);
    link2 = (RelativeLayout) findViewById(R.id.link2);
    link3 = (RelativeLayout) findViewById(R.id.link3);
    link4 = (RelativeLayout) findViewById(R.id.link4);
    link5 = (RelativeLayout) findViewById(R.id.link5);
    link6 = (RelativeLayout) findViewById(R.id.link6);
    link7 = (RelativeLayout) findViewById(R.id.link7);
    link1.setOnClickListener(this);
    link2.setOnClickListener(this);
    link3.setOnClickListener(this);
    link4.setOnClickListener(this);
    link5.setOnClickListener(this);
    link6.setOnClickListener(this);
    link7.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.link1:
         linkFunction("http://changevssame.blogspot.com/2014/03/willow-cricket-hd-live-streaming.html");

        break;
    case R.id.link2:
        linkFunction("http://changevssame.blogspot.com/2014/03/foxsports-live-streaming.html");
        break;
    case R.id.link3:
        linkFunction("http://changevssame.blogspot.com/2014/03/sky-sports-live-streaming.html");
        break;
    case R.id.link4:
        linkFunction("http://changevssame.blogspot.com/2014/03/ten-sports-live-streaming.html");
        break;
    case R.id.link5:
        linkFunction("http://changevssame.blogspot.com/2014/03/star-cricket.html");
        break;
    case R.id.link6:
        linkFunction("http://changevssame.blogspot.com/2014/03/icc-t20-world-cup-2014-live-streaming.html");
        break;
    case R.id.link7:
        linkFunction("http://changevssame.blogspot.com/2014/03/ptv-sports.html");
        break;

    default:
        break;
    }

解决方案

I will try to answer your questions but there are many fundamentals you've got to learn in order to build up a successful Streaming Application.

1. From where I can found the links to play cricket streaming ?

No idea, but this is not a SO standard question anyway.

2. Which type of links are these ?

IF you mean live streaming links, there are many types but mostly they are either HLS or RTSP. HLS links are simple HTTP links that often end with a ".m3u8" post-fix. (e.g "http://somewebsite.com/streams/hls_stream_video.m3u8")

RTSP links on the other hand, have a format like this: "rtsp://somewebsite.com/streams/an_rtsp_stream.mp4"

3. Is there any player to play this type of videos ?

Absolutely. You can do so by any means. I'm not exactly sure by "a player" whether you mean Android API player or third-party player applications. So I'll cover both cases for you and future passengers.

I) Android API: You can do so with the help of a MediaController, a MediaPlayer and a SurafceView. The latter two are also available in a unit entity known as VideoView. There is a code in the answer below, you can use that. But Be aware of two key-notes:

I-a) Using MediaPlayer is harder to implement but gives you more detailed control compared to VideoView.

I-b) If you use some code similar to the below answer Never call prepare() for network streams. Always prepareAsync(). And Always call setAudioStreamType() before prepareAsync. Otherwise you will face transient sync issues between Audio and Video when seeking on the progressbar.

II) Player Application: I have done streaming with MXPlayer and it works great.

There are some considerations to take before starting:

What protocol to choose?

Assuming you are targeting Android, I can advice you to narrow your choices down to HLS and RTSP. You need to study them well before making a decision. But to give you a hint. HLS is preferred when functioning on lower Bandwidths.

There are many other topics like whether to choose UDP/TCP, IP-Multicast/Broadcast and so on...

Want to delve into coding and learn Video Streaming programmatically?

Go and visit this tutorial. This is the most complete zero-to-hero guide in my opinion.


Since SO lacks a thorough post on Video Streaming, maybe I will extend my answer on demand.

这篇关于如何在Android应用程序播放流媒体直播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆