@tencent-rtc/mcp 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/resource/doc/chatuikit/faq/common/server.md +44 -0
- package/resource/doc/chatuikit/faq/web_sdk/faq.md +57 -0
- package/resource/doc/livekit/vue/components/co-guest-panel.md +3 -3
- package/resource/doc/livekit/vue/components/live-view.md +4 -4
- package/resource/doc/livekit/vue/{components/live-list.md → live-list-integration.md} +7 -7
- package/resource/doc/livekit/vue/{components/live-player.md → live-player-desk-integration.md} +8 -8
- package/resource/doc/livekit/vue/live-player-h5-integration.md +269 -0
- package/resource/doc/livekit/vue/workflow.md +218 -0
- package/resource/doc/native_live/android/V2TXLiveCode_api_android.md +312 -0
- package/resource/doc/native_live/android/V2TXLiveDef_api_android.md +430 -0
- package/resource/doc/native_live/android/V2TXLivePlayerObserver_api_android.md +679 -0
- package/resource/doc/native_live/android/V2TXLivePlayer_api_android.md +671 -0
- package/resource/doc/native_live/android/V2TXLivePremier_api_android.md +271 -0
- package/resource/doc/native_live/android/V2TXLivePusherObserver_api_android.md +849 -0
- package/resource/doc/native_live/android/V2TXLivePusher_api_android.md +1046 -0
- package/resource/doc/native_live/flutter/V2TXLiveCode_api_flutter.md +460 -0
- package/resource/doc/native_live/flutter/V2TXLiveDef_api_flutter.md +558 -0
- package/resource/doc/native_live/flutter/V2TXLivePlayerObserver_api_flutter.md +865 -0
- package/resource/doc/native_live/flutter/V2TXLivePlayer_api_flutter.md +657 -0
- package/resource/doc/native_live/flutter/V2TXLivePremier_api_flutter.md +437 -0
- package/resource/doc/native_live/flutter/V2TXLivePusherObserver_api_flutter.md +335 -0
- package/resource/doc/native_live/flutter/V2TXLivePusher_api_flutter.md +748 -0
- package/resource/doc/native_live/iOS/V2TXLiveCode_api_iOS.md +327 -0
- package/resource/doc/native_live/iOS/V2TXLiveDef_api_iOS.md +507 -0
- package/resource/doc/native_live/iOS/V2TXLivePlayerObserver_api_iOS.md +507 -0
- package/resource/doc/native_live/iOS/V2TXLivePlayer_api_iOS.md +659 -0
- package/resource/doc/native_live/iOS/V2TXLivePremier_api_iOS.md +284 -0
- package/resource/doc/native_live/iOS/V2TXLivePusherObserver_api_iOS.md +814 -0
- package/resource/doc/native_live/iOS/V2TXLivePusher_api_iOS.md +1000 -0
- package/resource/doc/trtc/C++/ITRTCCloud.md +4119 -0
- package/resource/doc/trtc/C++/ITRTCStatistics.md +325 -0
- package/resource/doc/trtc/C++/ITXAudioEffectManager.md +1289 -0
- package/resource/doc/trtc/C++/ITXDeviceManager.md +1028 -0
- package/resource/doc/trtc/C++/TRTCCloudCallback.md +2650 -0
- package/resource/doc/trtc/C++/TRTCTypeDef.md +3600 -0
- package/resource/doc/trtc/C++/TXLiteAVCode.md +921 -0
- package/resource/doc/trtc/android/TRTCCloud.md +3782 -0
- package/resource/doc/trtc/android/TRTCCloudDef.md +3880 -0
- package/resource/doc/trtc/android/TRTCCloudListener.md +2431 -0
- package/resource/doc/trtc/android/TRTCStatistics.md +295 -0
- package/resource/doc/trtc/android/TXAudioEffectManager.md +1289 -0
- package/resource/doc/trtc/android/TXBeautyManager.md +979 -0
- package/resource/doc/trtc/android/TXDeviceManager.md +440 -0
- package/resource/doc/trtc/android/TXLiteAVCode.md +905 -0
- package/resource/doc/trtc/iOS/TRTCCloud.md +4238 -0
- package/resource/doc/trtc/iOS/TRTCCloudDef.md +3730 -0
- package/resource/doc/trtc/iOS/TRTCCloudDelegate.md +2531 -0
- package/resource/doc/trtc/iOS/TRTCStatistics.md +295 -0
- package/resource/doc/trtc/iOS/TXAudioEffectManager.md +1100 -0
- package/resource/doc/trtc/iOS/TXBeautyManager.md +985 -0
- package/resource/doc/trtc/iOS/TXDeviceManager.md +1024 -0
- package/resource/doc/trtc/iOS/TXLiteAVCode.md +928 -0
- package/tools/definitions/get_faq_def.js +4 -0
- package/tools/definitions/get_faq_def.js.map +1 -1
- package/tools/definitions/get_native_live_api_def.js +23 -0
- package/tools/definitions/get_native_live_api_def.js.map +1 -0
- package/tools/definitions/get_trtc_native_api_def.js +16 -0
- package/tools/definitions/get_trtc_native_api_def.js.map +1 -0
- package/tools/definitions/get_web_live_uikit_component_detail_def.js +13 -8
- package/tools/definitions/get_web_live_uikit_component_detail_def.js.map +1 -1
- package/tools/definitions/get_web_live_uikit_integration_def.js +32 -0
- package/tools/definitions/get_web_live_uikit_integration_def.js.map +1 -0
- package/tools/index.js +8 -0
- package/tools/index.js.map +1 -1
- package/tools/live/get-web-live-uikit-integration.js +52 -0
- package/tools/live/get-web-live-uikit-integration.js.map +1 -0
- package/tools/native_live/get-native-live-api.js +31 -0
- package/tools/native_live/get-native-live-api.js.map +1 -0
- package/tools/trtc/get-trtc-native-api.js +31 -0
- package/tools/trtc/get-trtc-native-api.js.map +1 -0
- package/utils/generate-structured-result.js +34 -0
- package/utils/generate-structured-result.js.map +1 -0
- package/utils/handle-component-name.js +0 -8
- package/utils/handle-component-name.js.map +1 -1
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
- /package/resource/doc/livekit/vue/{components/broadcast.md → live-pusher-integration.md} +0 -0
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
# Tencent Cloud Live Streaming SDK V2TXLivePlayer Playback API Documentation
|
|
2
|
+
|
|
3
|
+
## Feature Overview
|
|
4
|
+
|
|
5
|
+
`V2TXLivePlayer` is the primary interface for the Tencent Cloud Live Streaming (CSS) player. It handles pulling audio and video streams from a specified live stream URL, performs decoding, and renders playback on the local device.
|
|
6
|
+
|
|
7
|
+
**File Path**: `v2_tx_live_player.dart`
|
|
8
|
+
**Platform Support**: Flutter
|
|
9
|
+
|
|
10
|
+
## Core Features
|
|
11
|
+
|
|
12
|
+
### 🎯 Main Capabilities
|
|
13
|
+
- ✅ **Multi-Protocol Support**: HTTP-FLV, WebRTC, TRTC, HLS, RTMP
|
|
14
|
+
- ✅ **Video Controls**: Rotation, Fill Mode, Mirroring
|
|
15
|
+
- ✅ **Playback Controls**: Play/Stop, Pause/Resume, Volume Adjustment
|
|
16
|
+
- ✅ **Cache Optimization**: Automatic cache strategy adjustment
|
|
17
|
+
- ✅ **Seamless Switching**: Switch between streams of different resolutions without interruption
|
|
18
|
+
- ✅ **Custom Processing**: Monitor audio/video data and implement custom rendering
|
|
19
|
+
- ✅ **Advanced Features**: Snapshot, SEI message handling, Picture-in-picture, Local recording
|
|
20
|
+
|
|
21
|
+
### 🔧 Technical Highlights
|
|
22
|
+
- **Low Latency**: Optimized cache management and adaptive networking
|
|
23
|
+
- **High Compatibility**: Supports a wide range of video encoding formats and resolutions
|
|
24
|
+
- **Easy Integration**: Simple API design with comprehensive callback support
|
|
25
|
+
- **High Performance**: Hardware Decoding acceleration and efficient rendering pipeline
|
|
26
|
+
|
|
27
|
+
### Create Player Instance
|
|
28
|
+
```dart
|
|
29
|
+
V2TXLivePlayer player = await V2TXLivePlayer.create();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Details
|
|
33
|
+
|
|
34
|
+
### Basic Setup APIs
|
|
35
|
+
|
|
36
|
+
#### Add Listener
|
|
37
|
+
```dart
|
|
38
|
+
void addListener(V2TXLivePlayerObserver observer)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Parameters**:
|
|
42
|
+
- `observer`: Callback target, must implement the `V2TXLivePlayerObserver` interface
|
|
43
|
+
|
|
44
|
+
**When to Use**: Set immediately after initializing the player
|
|
45
|
+
|
|
46
|
+
**Description**: Register callbacks to monitor player state, playback volume, first frame events for audio/video, statistics, warnings, and errors.
|
|
47
|
+
|
|
48
|
+
**Example**:
|
|
49
|
+
```dart
|
|
50
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
51
|
+
onConnected: (player) {
|
|
52
|
+
print('Player connected');
|
|
53
|
+
},
|
|
54
|
+
onVideoPlaying: (player, isFirstPlay) {
|
|
55
|
+
print('Video started playing');
|
|
56
|
+
},
|
|
57
|
+
));
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Set Render View
|
|
61
|
+
```dart
|
|
62
|
+
Future<V2TXLiveCode> setRenderViewID(int viewID)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Parameters**:
|
|
66
|
+
- `viewID`: ID of the rendering view
|
|
67
|
+
|
|
68
|
+
**Return Value**: `V2TXLiveCode`
|
|
69
|
+
- `V2TXLIVE_OK`: Success
|
|
70
|
+
|
|
71
|
+
**When to Use**: Set before starting playback
|
|
72
|
+
|
|
73
|
+
**Example**:
|
|
74
|
+
```dart
|
|
75
|
+
await player.setRenderViewID(viewId);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Set Render Rotation
|
|
79
|
+
```dart
|
|
80
|
+
Future<V2TXLiveCode> setRenderRotation(V2TXLiveRotation rotation)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Parameters**:
|
|
84
|
+
- `rotation`: Rotation angle (`V2TXLiveRotation`)
|
|
85
|
+
- `v2TXLiveRotation0` [Default]: 0°, no rotation
|
|
86
|
+
- `v2TXLiveRotation90`: 90° clockwise
|
|
87
|
+
- `v2TXLiveRotation180`: 180° clockwise
|
|
88
|
+
- `v2TXLiveRotation270`: 270° clockwise
|
|
89
|
+
|
|
90
|
+
**Return Value**: `V2TXLiveCode`
|
|
91
|
+
- `V2TXLIVE_OK`: Success
|
|
92
|
+
|
|
93
|
+
**When to Use**: Any time
|
|
94
|
+
|
|
95
|
+
**Example**:
|
|
96
|
+
```dart
|
|
97
|
+
await player.setRenderRotation(V2TXLiveRotation.v2TXLiveRotation0);
|
|
98
|
+
await player.setRenderRotation(V2TXLiveRotation.v2TXLiveRotation90);
|
|
99
|
+
await player.setRenderRotation(V2TXLiveRotation.v2TXLiveRotation180);
|
|
100
|
+
await player.setRenderRotation(V2TXLiveRotation.v2TXLiveRotation270);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Set Render Fill Mode
|
|
104
|
+
```dart
|
|
105
|
+
Future<V2TXLiveCode> setRenderFillMode(V2TXLiveFillMode mode)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Parameters**:
|
|
109
|
+
- `mode`: Fill mode (`V2TXLiveFillMode`)
|
|
110
|
+
- `v2TXLiveFillModeFill` [Default]: Fills the screen, crops if aspect ratio differs
|
|
111
|
+
- `v2TXLiveFillModeFit`: Fits the entire image, may show black borders
|
|
112
|
+
- `v2TXLiveFillModeScaleFill`: Stretches image to fill screen, may distort aspect ratio
|
|
113
|
+
|
|
114
|
+
**Return Value**: `V2TXLiveCode`
|
|
115
|
+
- `V2TXLIVE_OK`: Success
|
|
116
|
+
|
|
117
|
+
**When to Use**: Any time
|
|
118
|
+
|
|
119
|
+
**Example**:
|
|
120
|
+
```dart
|
|
121
|
+
await player.setRenderFillMode(V2TXLiveFillMode.v2TXLiveFillModeFill);
|
|
122
|
+
await player.setRenderFillMode(V2TXLiveFillMode.v2TXLiveFillModeFit);
|
|
123
|
+
await player.setRenderFillMode(V2TXLiveFillMode.v2TXLiveFillModeScaleFill);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Playback Control APIs
|
|
127
|
+
|
|
128
|
+
#### Start Live Playback
|
|
129
|
+
```dart
|
|
130
|
+
Future<V2TXLiveCode> startLivePlay(String url)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Parameters**:
|
|
134
|
+
- `url`: Stream playback URL (supports HTTP-FLV, WebRTC, TRTC, HLS, RTMP)
|
|
135
|
+
|
|
136
|
+
**Return Value**: `V2TXLiveCode`
|
|
137
|
+
- `V2TXLIVE_OK`: Success, starts connecting and playback
|
|
138
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: Invalid URL
|
|
139
|
+
- `V2TXLIVE_ERROR_REFUSED`: RTC does not support pushing and pulling the same StreamId on the same device simultaneously
|
|
140
|
+
- `V2TXLIVE_ERROR_INVALID_LICENSE`: Invalid license, playback failed
|
|
141
|
+
|
|
142
|
+
**Important**:
|
|
143
|
+
- From version 10.7, you must set the License using `V2TXLivePremier.setLicence` before playback. Otherwise, playback will fail (black screen). Only set once globally.
|
|
144
|
+
- Supports Live Streaming License, Short Video License, and Video Playback License.
|
|
145
|
+
|
|
146
|
+
**When to Use**: Any time
|
|
147
|
+
|
|
148
|
+
**Example**:
|
|
149
|
+
```dart
|
|
150
|
+
V2TXLiveCode result = await player.startLivePlay("http://example.com/live/stream_1080p.flv");
|
|
151
|
+
if (result == V2TXLiveCode.V2TXLIVE_OK) {
|
|
152
|
+
print("Playback started successfully");
|
|
153
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_PARAMETER) {
|
|
154
|
+
print("Invalid playback URL");
|
|
155
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_REFUSED) {
|
|
156
|
+
print("Operation refused");
|
|
157
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_LICENSE) {
|
|
158
|
+
print("Invalid License, please check your License");
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Stop Playback
|
|
163
|
+
```dart
|
|
164
|
+
Future<V2TXLiveCode> stopPlay()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Return Value**: `V2TXLiveCode`
|
|
168
|
+
- `V2TXLIVE_OK`: Success
|
|
169
|
+
|
|
170
|
+
**When to Use**: After playback has started
|
|
171
|
+
|
|
172
|
+
**Example**:
|
|
173
|
+
```dart
|
|
174
|
+
await player.stopPlay();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Check Playback Status
|
|
178
|
+
```dart
|
|
179
|
+
Future<int> isPlaying()
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Return Value**:
|
|
183
|
+
- `1`: Currently playing
|
|
184
|
+
- `0`: Playback stopped
|
|
185
|
+
|
|
186
|
+
**When to Use**: Any time
|
|
187
|
+
|
|
188
|
+
**Example**:
|
|
189
|
+
```dart
|
|
190
|
+
int isPlaying = await player.isPlaying();
|
|
191
|
+
if (isPlaying == 1) {
|
|
192
|
+
print("Playing");
|
|
193
|
+
} else {
|
|
194
|
+
print("Playback stopped");
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Cache Control APIs
|
|
199
|
+
|
|
200
|
+
#### Set Cache Parameters
|
|
201
|
+
```dart
|
|
202
|
+
Future<V2TXLiveCode> setCacheParams(double minTime, double maxTime)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Parameters**:
|
|
206
|
+
- `minTime`: Minimum cache time (seconds), must be > 0 [Default: 1]
|
|
207
|
+
- `maxTime`: Maximum cache time (seconds), must be > 0 [Default: 5]
|
|
208
|
+
|
|
209
|
+
**Return Value**: `V2TXLiveCode`
|
|
210
|
+
- `V2TXLIVE_OK`: Success
|
|
211
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: minTime and maxTime must be greater than 0
|
|
212
|
+
|
|
213
|
+
**Optimization Tips**:
|
|
214
|
+
- **Stable Network**: Use a smaller cache (1–3 seconds)
|
|
215
|
+
- **Unstable Network**: Use a larger cache (3–5 seconds)
|
|
216
|
+
- **No Special Requirements**: Use default values
|
|
217
|
+
|
|
218
|
+
**When to Use**: Any time
|
|
219
|
+
|
|
220
|
+
**Example**:
|
|
221
|
+
```dart
|
|
222
|
+
await player.setCacheParams(1, 5);
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Advanced Feature APIs
|
|
226
|
+
|
|
227
|
+
#### Switch Stream
|
|
228
|
+
```dart
|
|
229
|
+
Future<V2TXLiveCode> switchStream(String newUrl)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Parameters**:
|
|
233
|
+
- `newUrl`: URL of the new stream with different resolution
|
|
234
|
+
|
|
235
|
+
**Return Value**: `V2TXLiveCode`
|
|
236
|
+
- `V2TXLIVE_OK`: Success
|
|
237
|
+
|
|
238
|
+
**When to Use**: After playback has started
|
|
239
|
+
|
|
240
|
+
**Example**:
|
|
241
|
+
```dart
|
|
242
|
+
await player.startLivePlay("http://example.com/live/stream_1080p.flv");
|
|
243
|
+
|
|
244
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
245
|
+
onStreamSwitched: (player, url, code) {
|
|
246
|
+
if (code == 0) {
|
|
247
|
+
print("Switch successful");
|
|
248
|
+
} else if (code == -1) {
|
|
249
|
+
print("Switch timeout");
|
|
250
|
+
} else if (code == -2) {
|
|
251
|
+
print("Switch failed, server error");
|
|
252
|
+
} else if (code == -3) {
|
|
253
|
+
print("Switch failed, client error");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
));
|
|
257
|
+
await player.switchStream("http://example.com/live/stream_720p.flv");
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Cache Control
|
|
261
|
+
|
|
262
|
+
#### Set Cache Parameters
|
|
263
|
+
**Feature**: Configure minimum and maximum cache times for automatic adjustment
|
|
264
|
+
```dart
|
|
265
|
+
Future<V2TXLiveCode> setCacheParams(double minTime, double maxTime)
|
|
266
|
+
```
|
|
267
|
+
**Parameters**:
|
|
268
|
+
- `minTime`: Minimum cache time (seconds), must be > 0, default: 1
|
|
269
|
+
- `maxTime`: Maximum cache time (seconds), must be > 0, default: 5
|
|
270
|
+
|
|
271
|
+
**Error Codes**:
|
|
272
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: minTime and maxTime must be greater than 0
|
|
273
|
+
- `V2TXLIVE_ERROR_REFUSED`: Cannot modify cache strategy while player is playing
|
|
274
|
+
|
|
275
|
+
#### Enable Volume Evaluation
|
|
276
|
+
```dart
|
|
277
|
+
Future<V2TXLiveCode> enableVolumeEvaluation(int intervalMs)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Parameters**:
|
|
281
|
+
- `intervalMs`: Interval for `onPlayoutVolumeUpdate` callback in ms. Minimum is 100ms. Set to 0 or less to disable. Recommended: 300ms [Default: 0, disabled]
|
|
282
|
+
|
|
283
|
+
**Description**: Enables SDK volume level evaluation via the `V2TXLivePlayerObserver` callback.
|
|
284
|
+
|
|
285
|
+
**Return Value**: `V2TXLiveCode`
|
|
286
|
+
- `V2TXLIVE_OK`: Success
|
|
287
|
+
|
|
288
|
+
**When to Use**: Any time
|
|
289
|
+
|
|
290
|
+
**Example**:
|
|
291
|
+
```dart
|
|
292
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
293
|
+
onPlayoutVolumeUpdate: (player, volume) {
|
|
294
|
+
print("Audio playback volume: $volume");
|
|
295
|
+
}
|
|
296
|
+
));
|
|
297
|
+
await player.enableVolumeEvaluation(300);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### Snapshot
|
|
301
|
+
```dart
|
|
302
|
+
Future<V2TXLiveCode> snapshot()
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Return Value**: `V2TXLiveCode`
|
|
306
|
+
- `V2TXLIVE_OK`: Success
|
|
307
|
+
- `V2TXLIVE_ERROR_REFUSED`: Cannot capture snapshot when player is stopped
|
|
308
|
+
|
|
309
|
+
**When to Use**: After playback has started
|
|
310
|
+
|
|
311
|
+
**Example**:
|
|
312
|
+
```dart
|
|
313
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
314
|
+
onSnapshotComplete: (player, image) {
|
|
315
|
+
// Handle snapshot
|
|
316
|
+
}
|
|
317
|
+
));
|
|
318
|
+
await player.snapshot();
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### Enable Custom Video Rendering
|
|
322
|
+
```dart
|
|
323
|
+
Future<V2TXLiveCode> enableObserveVideoFrame(bool enable, int pixelFormat, int bufferType)
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Parameters**:
|
|
327
|
+
- `enable`: Enable custom rendering [Default: false]
|
|
328
|
+
- `pixelFormat`: Pixel format for rendering callback (`V2TXLivePixelFormat`)
|
|
329
|
+
- `bufferType`: Data format for rendering callback (`V2TXLiveBufferType`)
|
|
330
|
+
|
|
331
|
+
**Description**:
|
|
332
|
+
- When enabled, SDK stops default video rendering. You can access video frames via `V2TXLivePlayerObserver` and implement your own rendering logic.
|
|
333
|
+
- Supported combinations:
|
|
334
|
+
- `V2TXLivePixelFormat.v2TXLivePixelFormatTexture2D`, `V2TXLiveBufferType.v2TXLiveBufferTypeTexture` (recommended)
|
|
335
|
+
- `V2TXLivePixelFormat.v2TXLivePixelFormatI420`, `V2TXLiveBufferType.v2TXLiveBufferTypeByteArray`
|
|
336
|
+
- `V2TXLivePixelFormat.v2TXLivePixelFormatI420`, `V2TXLiveBufferType.v2TXLiveBufferTypeByteBuffer`
|
|
337
|
+
|
|
338
|
+
**Return Value**: `V2TXLiveCode`
|
|
339
|
+
- `V2TXLIVE_OK`: Success
|
|
340
|
+
- `V2TXLIVE_ERROR_NOT_SUPPORTED`: Unsupported pixel or data format
|
|
341
|
+
|
|
342
|
+
**When to Use**: Before playback starts
|
|
343
|
+
|
|
344
|
+
**Example**:
|
|
345
|
+
```dart
|
|
346
|
+
await player.enableObserveVideoFrame(true,
|
|
347
|
+
V2TXLivePixelFormat.v2TXLivePixelFormatTexture2D,
|
|
348
|
+
V2TXLiveBufferType.v2TXLiveBufferTypeTexture);
|
|
349
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
350
|
+
onRenderVideoFrame: (player, videoFrame) {
|
|
351
|
+
// Custom rendering logic
|
|
352
|
+
}
|
|
353
|
+
));
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
#### Enable Audio Data Callback
|
|
357
|
+
```dart
|
|
358
|
+
Future<V2TXLiveCode> enableObserveAudioFrame(bool enable)
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Parameters**:
|
|
362
|
+
- `enable`: Enable audio data callback [Default: false]
|
|
363
|
+
|
|
364
|
+
**Description**: When enabled, access audio data via `V2TXLivePlayerObserver` for custom processing.
|
|
365
|
+
|
|
366
|
+
**Return Value**: `V2TXLiveCode`
|
|
367
|
+
- `V2TXLIVE_OK`: Success
|
|
368
|
+
|
|
369
|
+
**When to Use**: Before playback starts
|
|
370
|
+
|
|
371
|
+
**Example**:
|
|
372
|
+
```dart
|
|
373
|
+
await player.enableObserveAudioFrame(true);
|
|
374
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
375
|
+
onPlayoutAudioFrame: (player, audioFrame) {
|
|
376
|
+
// Custom audio processing
|
|
377
|
+
}
|
|
378
|
+
));
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### Enable SEI Message Reception
|
|
382
|
+
```dart
|
|
383
|
+
Future<V2TXLiveCode> enableReceiveSeiMessage(bool enable, int payloadType)
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Parameters**:
|
|
387
|
+
- `enable`: true to enable, false to disable [Default: false]
|
|
388
|
+
- `payloadType`: Supported values: 5, 242, 243. Must match sender's payloadType.
|
|
389
|
+
|
|
390
|
+
**Return Value**: `V2TXLiveCode`
|
|
391
|
+
- `V2TXLIVE_OK`: Success
|
|
392
|
+
|
|
393
|
+
**When to Use**: Before playback starts
|
|
394
|
+
|
|
395
|
+
**Example**:
|
|
396
|
+
```dart
|
|
397
|
+
await player.enableReceiveSeiMessage(true, 5);
|
|
398
|
+
await player.enableReceiveSeiMessage(true, 242);
|
|
399
|
+
await player.enableReceiveSeiMessage(true, 243);
|
|
400
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
401
|
+
onReceiveSeiMessage: (player, payloadType, data) {
|
|
402
|
+
// Handle SEI message
|
|
403
|
+
}
|
|
404
|
+
));
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Local Recording APIs
|
|
408
|
+
|
|
409
|
+
#### Start Local Recording
|
|
410
|
+
```dart
|
|
411
|
+
Future<V2TXLiveCode> startLocalRecording(V2TXLiveLocalRecordingParams params)
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Parameters**:
|
|
415
|
+
- `params`: See `V2TXLiveDef.dart` for details
|
|
416
|
+
|
|
417
|
+
**Important**:
|
|
418
|
+
- Start recording only after stream playback has begun; starting before pulling is invalid
|
|
419
|
+
- Do not switch between software and hardware decoding during recording, as this may corrupt video files
|
|
420
|
+
|
|
421
|
+
**Return Value**: `V2TXLiveCode`
|
|
422
|
+
- `V2TXLIVE_OK`: Success
|
|
423
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: Invalid parameter, e.g., empty filePath
|
|
424
|
+
- `V2TXLIVE_ERROR_REFUSED`: API refused, stream not started
|
|
425
|
+
|
|
426
|
+
**When to Use**: After playback has started
|
|
427
|
+
|
|
428
|
+
**Example**:
|
|
429
|
+
```dart
|
|
430
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
431
|
+
onLocalRecordBegin: (player, code, storagePath) {
|
|
432
|
+
print("Recording started");
|
|
433
|
+
},
|
|
434
|
+
onLocalRecording: (player, durationMs, storagePath) {
|
|
435
|
+
print("Recording..., durationMs: $durationMs");
|
|
436
|
+
},
|
|
437
|
+
onLocalRecordComplete: (player, code, storagePath) {
|
|
438
|
+
print("Recording completed");
|
|
439
|
+
}
|
|
440
|
+
));
|
|
441
|
+
|
|
442
|
+
V2TXLiveLocalRecordingParams params = V2TXLiveLocalRecordingParams(
|
|
443
|
+
filePath: "filepath",
|
|
444
|
+
interval: 2000
|
|
445
|
+
);
|
|
446
|
+
V2TXLiveCode code = await player.startLocalRecording(params);
|
|
447
|
+
if (code == V2TXLiveCode.V2TXLIVE_OK) {
|
|
448
|
+
print("Recording started successfully");
|
|
449
|
+
} else if (code == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_PARAMETER) {
|
|
450
|
+
print("Invalid recording parameters");
|
|
451
|
+
} else if (code == V2TXLiveCode.V2TXLIVE_ERROR_REFUSED) {
|
|
452
|
+
print("Recording operation refused");
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
#### Stop Local Recording
|
|
457
|
+
```dart
|
|
458
|
+
Future<void> stopLocalRecording()
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
**Description**: If playback stops during recording, the SDK will automatically end the recording.
|
|
462
|
+
|
|
463
|
+
**When to Use**: After playback and recording have started
|
|
464
|
+
|
|
465
|
+
**Example**:
|
|
466
|
+
```dart
|
|
467
|
+
await player.stopLocalRecording();
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Debugging and Advanced Configuration APIs
|
|
471
|
+
|
|
472
|
+
#### Show Debug View
|
|
473
|
+
```dart
|
|
474
|
+
Future<void> showDebugView(bool isShow)
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
**Parameters**:
|
|
478
|
+
- `isShow`: true to show debug overlay [Default: false]
|
|
479
|
+
|
|
480
|
+
**When to Use**: Any time
|
|
481
|
+
|
|
482
|
+
**Example**:
|
|
483
|
+
```dart
|
|
484
|
+
await player.showDebugView(true);
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
#### Set Advanced Property
|
|
488
|
+
```dart
|
|
489
|
+
Future<V2TXLiveCode> setProperty(String key, Object value)
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
**Parameters**:
|
|
493
|
+
- `key`: Advanced API key
|
|
494
|
+
- `value`: Value for the advanced API
|
|
495
|
+
|
|
496
|
+
**Description**: For advanced features. For specific requirements, contact your business representative or solution architect.
|
|
497
|
+
|
|
498
|
+
**Return Value**: `V2TXLiveCode`
|
|
499
|
+
- `V2TXLIVE_OK`: Success
|
|
500
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: Key cannot be null
|
|
501
|
+
|
|
502
|
+
**Example**:
|
|
503
|
+
```dart
|
|
504
|
+
await player.setProperty("key", "value");
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
## Usage Example
|
|
508
|
+
|
|
509
|
+
```dart
|
|
510
|
+
import 'package:tencent_trtc/v2_tx_live_player.dart';
|
|
511
|
+
import 'package:tencent_trtc/v2_tx_live_player_observer.dart';
|
|
512
|
+
import 'package:tencent_trtc/v2_tx_live_def.dart';
|
|
513
|
+
|
|
514
|
+
class LivePlayerExample {
|
|
515
|
+
late V2TXLivePlayer player;
|
|
516
|
+
|
|
517
|
+
// Initialize player
|
|
518
|
+
Future<void> initPlayer() async {
|
|
519
|
+
// Create player instance
|
|
520
|
+
player = await V2TXLivePlayer.create();
|
|
521
|
+
|
|
522
|
+
// Register player callbacks
|
|
523
|
+
player.addListener(V2TXLivePlayerObserver(
|
|
524
|
+
onConnected: (player) {
|
|
525
|
+
print('Player connected');
|
|
526
|
+
},
|
|
527
|
+
onVideoPlaying: (player, isFirstPlay) {
|
|
528
|
+
print('Video started playing');
|
|
529
|
+
},
|
|
530
|
+
onAudioPlaying: (player, isFirstPlay) {
|
|
531
|
+
print('Audio started playing');
|
|
532
|
+
},
|
|
533
|
+
onPlayoutVolumeUpdate: (player, volume) {
|
|
534
|
+
print('Playback volume updated: $volume');
|
|
535
|
+
},
|
|
536
|
+
onError: (player, code, msg, extraInfo) {
|
|
537
|
+
print('Player error: $code, $msg');
|
|
538
|
+
}
|
|
539
|
+
));
|
|
540
|
+
|
|
541
|
+
// Set rendering view
|
|
542
|
+
await player.setRenderViewID(viewId);
|
|
543
|
+
|
|
544
|
+
// Set rotation angle
|
|
545
|
+
await player.setRenderRotation(V2TXLiveRotation.v2TXLiveRotation0);
|
|
546
|
+
|
|
547
|
+
// Set fill mode
|
|
548
|
+
await player.setRenderFillMode(V2TXLiveFillMode.v2TXLiveFillModeFit);
|
|
549
|
+
|
|
550
|
+
// Set cache parameters
|
|
551
|
+
await player.setCacheParams(1.0, 5.0);
|
|
552
|
+
|
|
553
|
+
// Enable volume evaluation
|
|
554
|
+
await player.enableVolumeEvaluation(300);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Start playback
|
|
558
|
+
Future<void> startPlay(String url) async {
|
|
559
|
+
V2TXLiveCode result = await player.startLivePlay(url);
|
|
560
|
+
if (result == V2TXLiveCode.V2TXLIVE_OK) {
|
|
561
|
+
print('Playback started successfully');
|
|
562
|
+
} else {
|
|
563
|
+
print('Playback failed: $result');
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// Pause/Resume video
|
|
568
|
+
Future<void> toggleVideo() async {
|
|
569
|
+
int isPlaying = await player.isPlaying();
|
|
570
|
+
if (isPlaying == 1) {
|
|
571
|
+
await player.pauseVideo();
|
|
572
|
+
print('Video paused');
|
|
573
|
+
} else {
|
|
574
|
+
await player.resumeVideo();
|
|
575
|
+
print('Video resumed');
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Pause/Resume audio
|
|
580
|
+
Future<void> toggleAudio() async {
|
|
581
|
+
int isPlaying = await player.isPlaying();
|
|
582
|
+
if (isPlaying == 1) {
|
|
583
|
+
await player.pauseAudio();
|
|
584
|
+
print('Audio paused');
|
|
585
|
+
} else {
|
|
586
|
+
await player.resumeAudio();
|
|
587
|
+
print('Audio resumed');
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// Set volume
|
|
592
|
+
Future<void> setVolume(int volume) async {
|
|
593
|
+
await player.setPlayoutVolume(volume);
|
|
594
|
+
print('Volume set to: $volume');
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Switch stream
|
|
598
|
+
Future<void> switchStream(String newUrl) async {
|
|
599
|
+
await player.switchStream(newUrl);
|
|
600
|
+
print('Switching stream...');
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// Take snapshot
|
|
604
|
+
Future<void> takeSnapshot() async {
|
|
605
|
+
await player.snapshot();
|
|
606
|
+
print('Snapshot triggered');
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Stop playback
|
|
610
|
+
Future<void> stopPlay() async {
|
|
611
|
+
await player.stopPlay();
|
|
612
|
+
print('Playback stopped');
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Destroy player
|
|
616
|
+
void destroyPlayer() {
|
|
617
|
+
player.destroy();
|
|
618
|
+
print('Player destroyed');
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// Usage example
|
|
623
|
+
void main() async {
|
|
624
|
+
LivePlayerExample example = LivePlayerExample();
|
|
625
|
+
await example.initPlayer();
|
|
626
|
+
await example.startPlay('http://example.com/live/stream.flv');
|
|
627
|
+
await Future.delayed(Duration(seconds: 10));
|
|
628
|
+
await example.takeSnapshot();
|
|
629
|
+
await example.stopPlay();
|
|
630
|
+
example.destroyPlayer();
|
|
631
|
+
}
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
## Notes
|
|
635
|
+
|
|
636
|
+
1. **License Requirement**: Starting with version 10.7, you must set a valid License for playback to work.
|
|
637
|
+
2. **Permission Requirement**: Requires network and audio playback permissions.
|
|
638
|
+
3. **Lifecycle Management**: After creating an instance with `create()`, call `destroy()` to release resources.
|
|
639
|
+
4. **Observer Registration**: Register observers before playback to receive status callbacks.
|
|
640
|
+
5. **Error Handling**: All async methods return `V2TXLiveCode`; handle errors accordingly.
|
|
641
|
+
6. **Thread Safety**: Invoke API calls on the main thread.
|
|
642
|
+
7. **Resource Release**: Release resources promptly after playback ends to prevent memory leaks.
|
|
643
|
+
8. **Cache Strategy**: Adjust cache parameters based on network conditions for optimal playback.
|
|
644
|
+
|
|
645
|
+
## FAQs
|
|
646
|
+
|
|
647
|
+
### Q: Why does the player show a black screen with no video?
|
|
648
|
+
A: Verify that a valid License is set, the playback URL is correct, and the rendering view is properly configured.
|
|
649
|
+
|
|
650
|
+
### Q: Why is playback latency high?
|
|
651
|
+
A: Adjust cache parameters. For stable networks, use a smaller cache time (1–3 seconds).
|
|
652
|
+
|
|
653
|
+
### Q: How can I switch resolutions seamlessly?
|
|
654
|
+
A: Call the `switchStream()` method with a stream URL of a different resolution.
|
|
655
|
+
|
|
656
|
+
### Q: How do I get playback statistics?
|
|
657
|
+
A: Use the `onStatisticsUpdate` callback in `V2TXLivePlayerObserver`.
|