android流媒体开发全部详解 - Go语言中文社区

android流媒体开发全部详解


http://blog.csdn.net/jwzhangjie/article/details/9947559链接地址


关于直播的相关信息这里不做详解,我们对直播应该很熟悉,实现生活中有各种直播,他们如何实现的呢,其实开发一个简单不能简单的直播,只需要两个:1、直播地址 2、播放器,对于直播地址我们可以利用很多软件获取连接,播放器,现在开源的也有很多,最常见的就是ffmpeg,但是如果直接用ffmpeg开发工作量比较大,我们可以使用第三方的播放器库,例如vlc,vitamio等等,这里我使用的时vitamio库。

首先建立一个项目,命名为Live,项目建立好了以后我们需要配置vitamio需要的环境,网上有很多,这里就不写出了,添加了依赖库后添加一个主界面,这里我只添加了一个EditView和Button,配置如下:

 

[html] view plaincopy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".Live" >  
  10.   
  11.     <EditText  
  12.         android:id="@+id/live_url"  
  13.         android:layout_width="match_parent"  
  14.         android:layout_height="100dp" />  
  15.   
  16.     <Button  
  17.         android:id="@+id/play"  
  18.         android:layout_width="120dp"  
  19.         android:layout_height="60dp"  
  20.         android:layout_below="@id/live_url"  
  21.         android:layout_centerHorizontal="true"  
  22.         android:layout_marginTop="100dp"  
  23.         android:text="Play" >  
  24.     </Button>  
  25.   
  26. </RelativeLayout>  


主界面的类:

[java] view plaincopy
  1. package com.jwzhangjie.live;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.content.Intent;  
  6. import android.view.Menu;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.widget.Button;  
  10. import android.widget.EditText;  
  11.   
  12. public class Live extends Activity {  
  13.   
  14.     public static final String  DEFAULTPATH = "http://ipadlive.cntv.soooner.com/cctv_p2p_hdcctv6.m3u8";  
  15.     EditText Live_Url;  
  16.     Button PlayBtn;  
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.activity_live);  
  21.         Live_Url = (EditText)findViewById(R.id.live_url);  
  22.         Live_Url.setText(DEFAULTPATH);  
  23.         PlayBtn = (Button)findViewById(R.id.play);  
  24.         PlayBtn.setOnClickListener(new OnClickListener() {  
  25.             @Override  
  26.             public void onClick(View v) {  
  27.                 Intent intent = new Intent();  
  28.                 intent.setClass(Live.this, JieVideoPlayer.class);  
  29.                 String path = Live_Url.getText().toString();  
  30.                 if (path == null) {  
  31.                     path = DEFAULTPATH;  
  32.                 }  
  33.                 intent.putExtra("path", path);  
  34.                 startActivity(intent);  
  35.             }  
  36.         });  
  37.     }  
  38.   
  39.     @Override  
  40.     public boolean onCreateOptionsMenu(Menu menu) {  
  41.         getMenuInflater().inflate(R.menu.live, menu);  
  42.         return true;  
  43.     }  
  44.   
  45. }  


播放界面的类:

[java] view plaincopy
  1. package com.jwzhangjie.live;  
  2.   
  3. import io.vov.vitamio.LibsChecker;  
  4. import io.vov.vitamio.MediaPlayer;  
  5. import io.vov.vitamio.MediaPlayer.OnCompletionListener;  
  6. import io.vov.vitamio.MediaPlayer.OnInfoListener;  
  7. import io.vov.vitamio.widget.MediaController;  
  8. import io.vov.vitamio.widget.VideoView;  
  9. import android.annotation.SuppressLint;  
  10. import android.app.Activity;  
  11. import android.content.Context;  
  12. import android.content.pm.ActivityInfo;  
  13. import android.content.res.Configuration;  
  14. import android.media.AudioManager;  
  15. import android.net.Uri;  
  16. import android.os.Bundle;  
  17. import android.os.Handler;  
  18. import android.os.Message;  
  19. import android.util.Log;  
  20. 版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
    原文链接:https://blog.csdn.net/u012083681/article/details/22148663
    站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-04-19 16:41:42
  • 阅读 ( 1027 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢