V2TXLivePusher
. Platform | GitHub Address |
iOS | |
Android | |
Flutter |
public class MApplication extends Application {@Overridepublic void onCreate() {super.onCreate();String licenceURL = ""; // your licence urlString licenceKey = ""; // your licence keyV2TXLivePremier.setEnvironment("GDPR"); // set your environmentV2TXLivePremier.setLicence(this, licenceURL, licenceKey);V2TXLivePremier.setObserver(new V2TXLivePremierObserver() {@Overridepublic void onLicenceLoaded(int result, String reason) {Log.i(TAG, "onLicenceLoaded: result:" + result + ", reason:" + reason);}});}
<activityandroid:name="com.tencent.rtmp.video.TXScreenCapture$TXScreenCaptureAssistantActivity"android:theme="@android:style/Theme.Translucent"/>
// Specify the corresponding live broadcast protocol as RTMP, which does not support mic connectionV2TXLivePusher mLivePusher = new V2TXLivePusherImpl(this, V2TXLiveDef.V2TXLiveMode.TXLiveMode_RTMP);
// The push stream can be started according to the push stream protocol. RTMP cannot connect to the microphone. It should use rtmp:// to connect to the microphone.String url = "rtmp://test.com/live/streamid?txSecret=xxxxx&txTime=xxxxxxxx";mLivePusher.startMicrophone();mLivePusher.startScreenCapture();int ret = mLivePusher.startPush(url);if (ret == V2TXLIVE_ERROR_INVALID_LICENSE) {Log.i(TAG, "startRTMPPush: license verification failed");}
startPush
interface returns V2TXLIVE_ERROR_INVALID_LICENSE
, it means that your license verification failed, please check the url and key set in Step 2: Configure the SDK for license authorization.V2TXLivePusher
to add a watermark to videos output by the SDK. The position of the watermark is determined by the (x, y, scale)
parameter passed in.(x, y, scale)
parameter specifies the normalized coordinates of the watermark relative to the resolution of the published video. For example, if the resolution of the published video is 540 x 960, and (x, y, scale)
is set to (0.1, 0.1, 0.1)
, the actual pixel coordinates of the watermark will be (540 x 0.1, 960 x 0.1). The width of the watermark will be the video width x 0.1, and the height will be scaled automatically.// Set a video watermarkmLivePusher.setWatermark(BitmapFactory.decodeResource(getResources(),R.drawable.watermark), 0.03f, 0.015f, 1f);
setVideoQuality
in V2TXLivePusher
to set the quality of videos watched by audience. The encoding parameters set determine the quality of videos presented to audience. The local video watched by the host is the original HD version that has not been encoded or compressed, and is therefore not affected by the settings. For details, please see Setting Video Quality.V2TXLivePusherObserver
. The event indicates poor network conditions for hosts, which result in stuttering for audience. When this event occurs, you can send a UI message about poor network conditions to hosts, as shown above.@Overridepublic void onWarning(int code, String msg, Bundle extraInfo) {if (code == V2TXLiveCode.V2TXLIVE_WARNING_NETWORK_BUSY) {showNetBusyTips(); // Show a “network busy” message}}
V2TXLivePusher
outputs videos in portrait resolutions. You can output landscape-mode videos to audience by modifying a parameter of the setVideoQuality API.mLivePusher.setVideoQuality(mVideoResolution, isLandscape ? V2TXLiveVideoResolutionModeLandscape : V2TXLiveVideoResolutionModePortrait);
V2TXLivePusher
object running at a time, make sure that you release all the resources when stopping publishing.// Stop screen sharing and release the resourcespublic void stopPublish() {mLivePusher.stopScreenCapture();mLivePusher.setObserver(null);mLivePusher.stopPush();}
Event ID | Code | Description |
V2TXLIVE_ERROR_FAILED | -1 | A common error not yet classified |
V2TXLIVE_ERROR_INVALID_PARAMETER | -2 | An invalid parameter was passed in during API calling. |
V2TXLIVE_ERROR_REFUSED | -3 | The API call was rejected. |
V2TXLIVE_ERROR_NOT_SUPPORTED | -4 | The API cannot be called. |
V2TXLIVE_ERROR_INVALID_LICENSE | -5 | Failed to call the API due to invalid license. |
V2TXLIVE_ERROR_REQUEST_TIMEOUT | -6 | The server request timed out. |
V2TXLIVE_ERROR_SERVER_PROCESS_FAILED | -7 | The server could not handle your request. |
Event ID | Code | Description |
V2TXLIVE_WARNING_NETWORK_BUSY | 1101 | Bad network connection: data upload blocked due to limited upstream bandwidth. |
V2TXLIVE_WARNING_VIDEO_BLOCK | 2105 | Stuttering during video playback. |
V2TXLIVE_WARNING_CAMERA_START_FAILED | -1301 | Failed to turn the camera on. |
V2TXLIVE_WARNING_CAMERA_OCCUPIED | -1316 | The camera is occupied. Try a different camera. |
V2TXLIVE_WARNING_CAMERA_NO_PERMISSION | -1314 | No access to the camera. This usually occurs on mobile devices and may be because the user denied the access. |
V2TXLIVE_WARNING_MICROPHONE_START_FAILED | -1302 | Failed to turn the mic on. |
V2TXLIVE_WARNING_MICROPHONE_OCCUPIED | -1319 | The mic is occupied. This occurs when, for example, the user is having a call on the mobile device. |
V2TXLIVE_WARNING_MICROPHONE_NO_PERMISSION | -1317 | No access to the mic. This usually occurs on mobile devices and may be because the user denied the access. |
V2TXLIVE_WARNING_SCREEN_CAPTURE_NOT_SUPPORTED | -1309 | The system does not support screen sharing. |
V2TXLIVE_WARNING_SCREEN_CAPTURE_START_FAILED | -1308 | Failed to start screen recording. If this occurs on a mobile device, it may be because the user denied the access. |
V2TXLIVE_WARNING_SCREEN_CAPTURE_INTERRUPTED | -7001 | Screen recording was stopped by the system. |
Was this page helpful?