Catalog
1, Application Guide
Official website address: https://www.aliyun.com/product/live
preparation:
-
ICP filing in Alibaba cloud
Those who have been filed with other ISP s but have not been filed with Alibaba also need to be re accessed. It took about 7 days for me to complete the data here once. However, there is a pit here. Alibaba needs to record service number for filing, while live broadcasting does not provide record service number. After online manual consultation and work order consultation, the reply (2020 / 03 / 02) is that at present, only one ECS can be purchased (our server is not deployed in Alibaba cloud platform). Fortunately, the price is not expensive. I got a record service number every 200 years. -
OBSStudio
Test push flow during R & D
Click download: OBS studio -
PotPlayer\VLC Media Player
Test playback during R & D
Click to download: PotPlayer
Click download: VLC Media Player
2, Configure streaming address \ playback address
1. Enter the live console, click domain name management, and click Add domain name (domain name needs to be filed in Alibaba cloud first)
2. Add a streaming address and a playback address respectively (note that the two addresses need to be different)
3, Configure authentication information
Enter live console, click domain name management, and then configure streaming domain name and playing domain name respectively
1. Configure streaming domain name
a. Configure callback address
Official note: infer that the flow callback can perform real-time information callback of live stream status, and timely notify the user of the result of streaming push or disconnection operation.
Where https://live.aliyunlive.com/pub is the server address, which is the configured push flow callback address.
Example:
https://live.aliyunlive.com/pub? action=publish & app=xc.cdnpe.com & appname=test01 & id=test01 & ip=42.120.74.183 & node=cdnvideocenter010207116011.cm3
Parameter Description:
b. Access control
Click the same page access control, click Modify configuration in URL authentication, and then set a authentication KEY. 32-bit with case parameter is recommended.
2. Configure the playing domain name
a. Configure Https
Click HTTPS configuration and upload the certificate (if there is no certificate, please refer to another article of mine, and you can get the SSL certificate of alicloud for one year free)
b. The same as the streaming domain name, configure a playback authentication key (try not to be the same as the streaming domain name)
4, Test playback
1. Use the address generator to generate a push and play address
Enter an AppName(Path) and StreamName(Filename), and click generate to get the streaming address and playback address, which are lost in OBS and Potplayer respectively, to test whether the streaming can be pushed or pulled normally. (the tools will be explained later in this article)
2. Assemble the push-pull stream address by yourself
First look at the official documents:
for example
Domain name: live.test.com
AppName: app
StreamName: test
Timestamp: 1583133237 (10 bit seconds, within the first 30 minutes of the timestamp, the authentication key is valid)
rand: 477b3bbc253f467b8def6711128c7bec (a user-defined random character, the UUID of - is officially recommended to be removed. To further ensure the security of the authentication Key, the test here shows that the same first-class, streaming rand and playing rand can be different)
uid: 0 (official note: not used, set to 0)
Authentication Key: 123456 (note that authentication keys for streaming and playing are different, as explained above)
After the combined address:
rtmp://live.test.com/app/test?auth_key=timestamp-rand-uid-md5hash
The generation method of md5hash is as follows:
URI-Timestamp-rand-uid-PrivateKey(URI Is the relative address of the user's request object, excluding parameters, such as:/Filename)
HashValue = md5sum(sstring)
That is:
/app/test-1583133237-477b3bbc253f467b8def6711128c7bec-0-123456
Take md5 lowercase (note lowercase) = e732852bdc84dac82f055cff833f7e1, that is, PrivateKey
The final address is:
rtmp://live.test.com/app/test?auth_key=1583133237-477b3bbc253f467b8def6711128c7bec-0-e732852bdc84dac82f055cfff833f7e1
Push stream and play are generated in the same way.
5, Use of OBSStudio and PotPlayer
1. OBSStudio
Open OBS studio, click file - settings (or settings in the lower right corner) - switch to the [streaming] tab, change the service to user-defined, and the server can enter the streaming address.
Then add a new source, the test camera is better, easy to observe and judge the details.
Finally, after clicking start streaming, there is no error prompt in the lower left corner, and there is flow in the lower right corner, that is, the streaming is successfully pushed.
2. PotPlayer
When you are sure that you are streaming, open PotPlayer and enter the playback address.
6, Simple integration of Android playback
Here, use the playback SDK provided by Alibaba cloud: https://help.aliyun.com/document_detail/125579.html?spm=a2c4g.11186623.2.7.3b656381pv9iGi
1. Introduction module
Project build.gradle
allprojects { repositories { google() jcenter() mavenCentral() // Add aliyuan maven {url 'https://maven.aliyun.com/repository/releases'} } }
App build.grade
dependencies { //https://help.aliyun.com/document_detail/124711.html?spm=a2c4g.11186623.6.1079.a9ea1bc7WxDrpL //https://maven.aliyun.com/mvn/search implementation 'com.aliyun.sdk.android:AliyunPlayer:4.7.3-full' implementation 'com.alivc.conan:AlivcConan:1.0.2.1' }
2. Activity source code
package com.itxca.test.live; import android.graphics.Bitmap; import android.view.SurfaceHolder; import android.view.SurfaceView; import com.aliyun.player.AliPlayer; import com.aliyun.player.AliPlayerFactory; import com.aliyun.player.IPlayer; import com.aliyun.player.bean.ErrorInfo; import com.aliyun.player.bean.InfoBean; import com.aliyun.player.nativeclass.TrackInfo; import com.aliyun.player.source.UrlSource; import com.itxca.test.R; import com.itxca.test.ui.bases.BaseActivity; /** * Project Name : test * Package Name : com.itxca.test.live * Create Time : 2020-03-02 11:05 * Create By : @author xIao * Version : 1.0.0 **/ public class AliPlayActivity extends BaseActivity { private SurfaceView surfaceView; private AliPlayer aliyunVodPlayer; @Override public boolean isRegEventBus() { return false; } @Override protected int getLayoutId() { return R.layout.activity_tx_play; } @Override protected int getTitleBarId() { return R.id.tb_title; } @Override protected void onDestroy() { super.onDestroy(); if (aliyunVodPlayer != null) { aliyunVodPlayer.release(); } } @Override protected void initView() { setTitle("Live broadcast"); } @Override protected void initData() { initPlayer(); initSourceData(); } private void initSourceData() { //Create VidSts UrlSource urlSource =new UrlSource(); urlSource.setTitle("Test 001"); //Replace this address with your playback address urlSource.setUri("rtmp://live.test.com/app/test?auth_key=1583119273-0-0-82d0b07300f2bd4aef2df7da0adf9798"); //Set playback source aliyunVodPlayer.setDataSource(urlSource); //Ready to play aliyunVodPlayer.prepare(); //play aliyunVodPlayer.start(); } private void initPlayer() { //If the played video is a local file downloaded safely through the player SDK, you need to set an encryption verification information (it is recommended to configure it once in the Application): //Privateservice. Initservice (getapplicationcontext(), "local path of encryptedapp. Dat"); //Create player aliyunVodPlayer = AliPlayerFactory.createAliPlayer(getApplicationContext()); //Binding view surfaceView = findViewById(R.id.sv_live_player); surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { aliyunVodPlayer.setDisplay(holder); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { aliyunVodPlayer.redraw(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { aliyunVodPlayer.setDisplay(null); } }); //Set callback aliyunVodPlayer.setOnCompletionListener(new IPlayer.OnCompletionListener() { @Override public void onCompletion() { //Play completion event } }); aliyunVodPlayer.setOnErrorListener(new IPlayer.OnErrorListener() { @Override public void onError(ErrorInfo errorInfo) { //Error Event } }); aliyunVodPlayer.setOnPreparedListener(new IPlayer.OnPreparedListener() { @Override public void onPrepared() { //Prepare for success events } }); aliyunVodPlayer.setOnVideoSizeChangedListener(new IPlayer.OnVideoSizeChangedListener() { @Override public void onVideoSizeChanged(int width, int height) { //Video resolution change callback } }); aliyunVodPlayer.setOnRenderingStartListener(new IPlayer.OnRenderingStartListener() { @Override public void onRenderingStart() { //First frame rendering display event } }); aliyunVodPlayer.setOnInfoListener(new IPlayer.OnInfoListener() { @Override public void onInfo(InfoBean infoBean) { //Other information events, including: cycle play start, buffer position, current play position, auto play start, etc } }); aliyunVodPlayer.setOnLoadingStatusListener(new IPlayer.OnLoadingStatusListener() { @Override public void onLoadingBegin() { //Buffer start. } @Override public void onLoadingProgress(int percent, float kbps) { //Buffer progress } @Override public void onLoadingEnd() { //Buffer end } }); aliyunVodPlayer.setOnSeekCompleteListener(new IPlayer.OnSeekCompleteListener() { @Override public void onSeekComplete() { //Drag end } }); aliyunVodPlayer.setOnSubtitleDisplayListener(new IPlayer.OnSubtitleDisplayListener() { @Override public void onSubtitleShow(long id, String data) { //Show Subtitles } @Override public void onSubtitleHide(long id) { //closed caption } }); aliyunVodPlayer.setOnTrackChangedListener(new IPlayer.OnTrackChangedListener() { @Override public void onChangedSuccess(TrackInfo trackInfo) { //Audio and video stream or definition successfully switched } @Override public void onChangedFail(TrackInfo trackInfo, ErrorInfo errorInfo) { //Failed to switch audio and video stream or definition } }); aliyunVodPlayer.setOnStateChangedListener(new IPlayer.OnStateChangedListener() { @Override public void onStateChanged(int newState) { //Player state change event } }); aliyunVodPlayer.setOnSnapShotListener(new IPlayer.OnSnapShotListener() { @Override public void onSnapShot(Bitmap bm, int with, int height) { //Screenshots } }); } }
3. Layout source code
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/layout_titlebar" /> <include layout="@layout/layout_state" /> <SurfaceView android:id="@+id/sv_live_player" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
Seven, summary
The basic integration of alicloud live broadcasting is basically finished. There are many examples of Github when streaming, so we won't go into details. In fact, you can play without using Alibaba's SDK, as long as the player supports Rtmp, Flv or M3U8.
The simple integration will be very fast. One hour after the domain name is recorded successfully, the push-pull stream can be debugged and the test live broadcast can be completed. But there are many details in Ali's settings, including automatic screenshots, recording and broadcasting, etc., which are all described in detail by the official. Just do it later.
I spent a lot of time in the whole integration process. I didn't notice that the authentication key s of push flow and pull flow are different, resulting in the generated flow being unusable all the time. Please don't roll over here.
The original post address, reprint please indicate: https://blog.csdn.net/hx7013/article/details/104611262