public class AlivcLivePusher
extends java.lang.Object
implements com.alivc.live.pusher.ILivePusher
关于AlivcLivePusher的主题有:
音视频推流的控制按照状态机进行管理。下面的状态图展示了一个AlivcLivePusher对象在使用过程中的完整的生命周期和状态变化。
方法名 | 有效状态 | 无效状态 | 备注 |
init | {Idle, Initialized} | {Previewed, Pushed, Paused, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
destroy | any | {} | 调用此方法之后,状态变为{Idle} |
startPreview | {Initialized, Previewed} | {Idle, Pushed, Paused, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Previewed |
startPreviewAysnc | {Initialized, Previewed} | {Idle, Pushed, Paused, Error,} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Previewed |
stopPreview | {Initialized, Previewed} | {Idle, Pushed, Paused, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
startPush | {Initialized, Previewed, Pushed} | {Idle,Paused, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Pushed |
startPushAysnc | {Initialized, Previewed, Pushed} | {Idle, Paused, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Pushed |
restartPush | {Pushed, Error} | {Idle, Initialized, Previewed, Paused} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Pushed |
restartPushAync | {Pushed, Error} | {Idle, Initialized, Previewed, Paused,} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Pushed |
reconnectPushAsync | {Pushed, Paused} | {Idle, Initialized, Previewed, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
stopPush | {Previewed, Pushed,Error} | {Idle, Initialized, Previewed, Pushed, Paused} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
pause | {Pushed,Paused,Previewed} | {Idle, Initialized, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
resume | {Paused,Pushed,Previewed,Initialized} | {Idle, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
resumeAsync | {Paused,Pushed,Previewed,Initialized} | {Idle, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态变为Initialized |
setBeautyOn | {Previewed, Pushed, Paused,} | {Idle, Initialized, Error} | 无效的状态调用此方法,状态不变。在有效的状态下调用此方法,状态不变 |
这个类需要 {android.permission.CAMERA} {android.permission.RECORD_AUDIO} 权限
在Activity的onPause和onResume的时候,需要调用pause和resume函数来应对处理处理前后台切换、锁屏、界面跳转及电话等场景。
在使用推流SDK的过程中,有以下几个接口由于涉及到硬解和网络,导致接口调用时间消耗可能会较长,因此我们同时也提供了异步接口。此外,我们还提供了一个异步的重连接口方便来处理网络错误。
在调用接口的时候,有的接口会抛出 IllegalArgumentException 和 IllegalStateException
构造器和说明 |
---|
AlivcLivePusher() |
限定符和类型 | 方法和说明 |
---|---|
void |
destroy()
释放推流
|
void |
focusCameraAtAdjustedPoint(float x,
float y,
boolean autoFocus)
对焦,对焦点的坐标x[0,屏幕宽度],y[0,屏幕宽度]
|
int |
getCurrentZoom()
获取当前缩放值
|
AlivcLivePushStatsInfo |
getLivePushStatsInfo()
获取推流统计数据
|
int |
getMaxZoom()
获取摄像头支持的最大缩放值, 0 : 不支持缩放 大于0 : 最大缩放值
|
java.lang.String |
getPushUrl()
获取推流URL
|
static java.lang.String |
getSDKVersion()
获取SDK版本号
|
void |
init(Context context,
AlivcLivePushConfig config)
初始化推流参数
|
boolean |
isCameraSupportAutoFocus()
获取是否支持自动对焦
|
boolean |
isCameraSupportFlash()
获取是否支持闪光灯
|
boolean |
isPushing()
是否正在推流
|
void |
pause()
暂停推流
|
void |
reconnectPushAsync()
重新连接进行推流
|
void |
restartPush()
重新开始推流
|
void |
restartPushAync()
重新开始推流
|
void |
resume()
恢复推流
|
void |
resumeAsync()
异步恢复推流
|
void |
setAutoFocus(boolean autoFocus)
设置自动对焦
|
void |
setBeautyBrightness(int beautyBrightness)
设置美颜亮度[0,100]
|
void |
setBeautyBuffing(int beautyBuffing)
改变磨皮程度[0,100]
|
void |
setBeautyOn(boolean beautyOn)
设置美颜开关
|
void |
setBeautyRuddy(int beautyRuddy)
设置美颜红润[0,100]
|
void |
setBeautySaturation(int beautySaturation)
设置美颜饱和度[0,100]
|
void |
setBeautyWhite(int beautyWhite)
改变美白程度[0,100]
|
void |
setFlash(boolean flash)
是否打开闪光灯
|
void |
setLivePushErrorListener(AlivcLivePushErrorListener errorListener)
设置推流错误事件
|
void |
setLivePushInfoListener(AlivcLivePushInfoListener infoListener)
设置推流通知事件
|
void |
setLivePushNetworkListener(AlivcLivePushNetworkListener networkListner) |
void |
setLogLevel(com.alivc.live.pusher.AlivcLivePushLogLevel level)
设置日志级别
|
void |
setMaxVideoBitrate(int maxVideoBitrate)
设置最大视频码率[100,5000](Kbps)
|
void |
setMinVideoBitrate(int minVideoBitrate)
设置最小视频码率[100,5000] (Kbps)
|
void |
setMute(boolean mute)
是否静音
|
void |
setPreviewMirror(boolean mirror)
预览镜像开关
|
void |
setPreviewOrientation(AlivcPreviewOrientationEnum orientation)
设置推流方向,默认竖屏
|
void |
setPushMirror(boolean mirror)
推流端是否水平镜像
|
void |
setZoom(int zoom)
设置缩放[0,getMaxZoom()]
|
void |
startPreview(SurfaceView surfaceView)
开始预览
|
void |
startPreviewAysnc(SurfaceView surfaceView)
异步开始预览
|
void |
startPush(java.lang.String url)
开始推流
|
void |
startPushAysnc(java.lang.String url)
开始推流
|
void |
stopPreview()
结束预览
|
void |
stopPush()
结束推流
|
void |
switchCamera()
切换摄像头
|
public void init(Context context, AlivcLivePushConfig config) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
init
在接口中 com.alivc.live.pusher.ILivePusher
context
- 上下文config
- 配置java.lang.IllegalArgumentException
- 如果 config为空,或者config的值为无效(例如码率的值超过范围)java.lang.IllegalStateException
- 如果状态不对,例如已经初始化,但是还没有销毁public void destroy() throws java.lang.IllegalStateException
destroy
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化public void startPreview(SurfaceView surfaceView) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
startPreview
在接口中 com.alivc.live.pusher.ILivePusher
surfaceView
- surfaceviewjava.lang.IllegalArgumentException
- 如果surfaceView为空,或者surfaceView的surface未创建/已销毁java.lang.IllegalStateException
- 如果状态不对,例如还未初始化public void startPreviewAysnc(SurfaceView surfaceView) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
startPreviewAysnc
在接口中 com.alivc.live.pusher.ILivePusher
surfaceView
- surfaceviewjava.lang.IllegalArgumentException
- 如果surfaceView为空,或者surfaceView的surface未创建/已销毁java.lang.IllegalStateException
- 如果状态不对,例如还未初始化public void stopPreview() throws java.lang.IllegalStateException
stopPreview
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void startPush(java.lang.String url) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
startPush
在接口中 com.alivc.live.pusher.ILivePusher
url
- 推流Urljava.lang.IllegalArgumentException
- 如果url为空,或者不是有效的url格式java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void startPushAysnc(java.lang.String url) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
startPushAysnc
在接口中 com.alivc.live.pusher.ILivePusher
url
- 推流Urljava.lang.IllegalArgumentException
- 如果url为空,或者不是有效的url格式java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void restartPush() throws java.lang.IllegalStateException
restartPush
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPush/已经stopPushpublic void restartPushAync() throws java.lang.IllegalStateException
restartPushAync
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPush/已经stopPushpublic void reconnectPushAsync() throws java.lang.IllegalStateException
reconnectPushAsync
在接口中 com.alivc.live.pusher.ILivePusher
IllegalStateException,例如还未初始化/未startPreview/未startPush/已经stopPush
java.lang.IllegalStateException
public void stopPush() throws java.lang.IllegalStateException
stopPush
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPush/已经stopPushpublic void pause() throws java.lang.IllegalStateException
pause
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPush/已经pausepublic void resume() throws java.lang.IllegalStateException
resume
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPush/未pause/已resumepublic void resumeAsync() throws java.lang.IllegalStateException
resumeAsync
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPush/未pause/已resumepublic void setBeautyOn(boolean beautyOn) throws java.lang.IllegalStateException
setBeautyOn
在接口中 com.alivc.live.pusher.ILivePusher
beautyOn
- true:打开美颜 falsh:关闭美颜java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setBeautyWhite(int beautyWhite) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setBeautyWhite
在接口中 com.alivc.live.pusher.ILivePusher
beautyWhite
- 0-100java.lang.IllegalArgumentException
- 如果输入参数值不在[0,100]java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setBeautyBuffing(int beautyBuffing) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setBeautyBuffing
在接口中 com.alivc.live.pusher.ILivePusher
beautyBuffing
- 0-100java.lang.IllegalArgumentException
- 如果输入参数值不在[0,100]java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setBeautyBrightness(int beautyBrightness) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setBeautyBrightness
在接口中 com.alivc.live.pusher.ILivePusher
beautyBrightness
- 美颜亮度java.lang.IllegalArgumentException
- 如果输入参数值不在[0,100]java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setBeautyRuddy(int beautyRuddy) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setBeautyRuddy
在接口中 com.alivc.live.pusher.ILivePusher
beautyRuddy
- 美颜红润java.lang.IllegalArgumentException
- 如果输入参数值不在[0,100]java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setBeautySaturation(int beautySaturation) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setBeautySaturation
在接口中 com.alivc.live.pusher.ILivePusher
beautySaturation
- 美颜饱和度java.lang.IllegalArgumentException
- 如果输入参数值不在[0,100]java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void switchCamera() throws java.lang.IllegalStateException
switchCamera
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setAutoFocus(boolean autoFocus) throws java.lang.IllegalStateException
setAutoFocus
在接口中 com.alivc.live.pusher.ILivePusher
autoFocus
- 自动聚焦java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void focusCameraAtAdjustedPoint(float x, float y, boolean autoFocus) throws java.lang.IllegalStateException
focusCameraAtAdjustedPoint
在接口中 com.alivc.live.pusher.ILivePusher
x
- 对焦的点x坐标y
- 对焦的点y坐标yautoFocus
- 是否自动聚焦java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setZoom(int zoom) throws java.lang.IllegalStateException
setZoom
在接口中 com.alivc.live.pusher.ILivePusher
zoom
- 0~getMaxZoom()java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic int getMaxZoom() throws java.lang.IllegalStateException
getMaxZoom
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic int getCurrentZoom() throws java.lang.IllegalStateException
getCurrentZoom
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setMute(boolean mute) throws java.lang.IllegalStateException
setMute
在接口中 com.alivc.live.pusher.ILivePusher
mute
- true:静音推流 false:正常推流java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPushpublic void setFlash(boolean flash) throws java.lang.IllegalStateException
setFlash
在接口中 com.alivc.live.pusher.ILivePusher
flash
- true:打开闪光灯 false:关闭闪光灯java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setPushMirror(boolean mirror) throws java.lang.IllegalStateException
setPushMirror
在接口中 com.alivc.live.pusher.ILivePusher
mirror
- true:打开推流镜像 false:关闭推流镜像java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPushpublic void setPreviewMirror(boolean mirror) throws java.lang.IllegalStateException
setPreviewMirror
在接口中 com.alivc.live.pusher.ILivePusher
mirror
- true:打开预览镜像 false:关闭预览镜像java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreviewpublic void setMaxVideoBitrate(int maxVideoBitrate) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setMaxVideoBitrate
在接口中 com.alivc.live.pusher.ILivePusher
maxVideoBitrate
- 最大视频编码码率java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPushjava.lang.IllegalArgumentException
public void setMinVideoBitrate(int minVideoBitrate) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
setMinVideoBitrate
在接口中 com.alivc.live.pusher.ILivePusher
minVideoBitrate
- 最小视频编码码率java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPushjava.lang.IllegalArgumentException
public boolean isCameraSupportAutoFocus()
isCameraSupportAutoFocus
在接口中 com.alivc.live.pusher.ILivePusher
public boolean isCameraSupportFlash()
isCameraSupportFlash
在接口中 com.alivc.live.pusher.ILivePusher
public boolean isPushing() throws java.lang.IllegalStateException
isPushing
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPushpublic void setLivePushErrorListener(AlivcLivePushErrorListener errorListener)
setLivePushErrorListener
在接口中 com.alivc.live.pusher.ILivePusher
errorListener
- 错误监听器public void setLivePushInfoListener(AlivcLivePushInfoListener infoListener)
setLivePushInfoListener
在接口中 com.alivc.live.pusher.ILivePusher
infoListener
- 通知监听器public void setLivePushNetworkListener(AlivcLivePushNetworkListener networkListner)
setLivePushNetworkListener
在接口中 com.alivc.live.pusher.ILivePusher
public static java.lang.String getSDKVersion()
public AlivcLivePushStatsInfo getLivePushStatsInfo() throws java.lang.IllegalStateException
getLivePushStatsInfo
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化public java.lang.String getPushUrl() throws java.lang.IllegalStateException
getPushUrl
在接口中 com.alivc.live.pusher.ILivePusher
java.lang.IllegalStateException
- 如果状态不对,例如还未初始化/未startPreview/未startPushpublic void setPreviewOrientation(AlivcPreviewOrientationEnum orientation)
setPreviewOrientation
在接口中 com.alivc.live.pusher.ILivePusher
orientation
- 推流方向public void setLogLevel(com.alivc.live.pusher.AlivcLivePushLogLevel level)
com.alivc.live.pusher.ILivePusher
setLogLevel
在接口中 com.alivc.live.pusher.ILivePusher