|
1 | 1 | --- |
2 | 2 | ## THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT. IF YOU NEED TO CHANGE THIS FILE, CREATE A PR IN THE SOURCE REPOSITORY. |
3 | | -title: api.video Android Player analytics plugin |
4 | | -meta: |
5 | | - description: The official api.video Android Player analytics plugin for api.video. [api.video](https://api.video/) is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app. |
| 3 | +title: api.video Android player analytics |
| 4 | +meta: |
| 5 | +description: The official api.video Android player analytics library for |
| 6 | +api.video. [api.video](https://api.video/) is the video infrastructure for product builders. |
| 7 | +Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live |
| 8 | +streaming features in your app. |
6 | 9 | --- |
7 | 10 |
|
8 | | -# api.video Android Player analytics plugin |
9 | | - |
10 | | -[api.video](https://api.video/) is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app. |
11 | 11 |
|
12 | 12 | ## Project description |
13 | 13 |
|
14 | | -Android library to manually call the api.video analytics collector. |
15 | | - |
16 | | -This is useful if you are using a video player for which we do not yet provide a ready-to-use |
17 | | -monitoring module. |
| 14 | +This library sends player events from the player to api.video. |
18 | 15 |
|
19 | 16 | ## Getting started |
20 | 17 |
|
21 | 18 | ### Installation |
22 | 19 |
|
23 | 20 | #### Gradle |
24 | 21 |
|
25 | | -In your module `build.gradle`, add the following code in `dependencies`: |
| 22 | +For ExoPlayer, add the following code in your module `build.gradle`: |
26 | 23 |
|
27 | 24 | ```groovy |
28 | 25 | dependencies { |
29 | | - implementation 'video.api:android-player-analytics:2.0.2' |
| 26 | + implementation 'video.api.player.analytics:android-player-analytics-exoplayer:3.0.0' |
30 | 27 | } |
31 | 28 | ``` |
32 | 29 |
|
33 | | -### Permissions |
34 | | - |
35 | | -In your `AndroidManifest.xml`, add the following code in `<manifest>`: |
36 | | - |
37 | | -```xml |
38 | | - |
39 | | -<uses-permission android:name="android.permission.INTERNET" /> |
40 | | -``` |
41 | | - |
42 | | -## Sample application |
43 | | - |
44 | | -A demo application demonstrates how to use player analytics library. |
45 | | -See [`/example`](https://github.com/apivideo/api.video-android-player-analytics/tree/main/example) |
46 | | -folder. |
47 | | - |
48 | | -## Documentation |
49 | | - |
50 | | -### Options |
51 | | - |
52 | | -The analytics module constructor takes a `Options` parameter that contains the following options: |
53 | | - |
54 | | -| Option name | Mandatory | Type | Description | |
55 | | -|--------------------:|-----------|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------| |
56 | | -| mediaUrl | ** | | | |
57 | | -| yes** | String | url of the media (eg. `https://vod.api.video/vod/vi5oDagRVJBSKHxSiPux5rYD/hls/manifest.m3u8`) | | |
58 | | -| videoInfo | ** | | | |
59 | | -| yes** | VideoInfo | information containing analytics collector url, video type (vod or live) and video id | | |
60 | | -| metadata | no | ```Map<String, String>``` | object containing [metadata](https://api.video/blog/tutorials/dynamic-metadata/) | |
61 | | -| onSessionIdReceived | no | ```((sessionId: String) -> Unit)?``` | callback called once the session id has been received | |
62 | | -| onPing | no | ```((message: PlaybackPingMessage) -> Unit)?``` | callback called before sending the ping message | |
63 | | - |
64 | | -Options instantiation is made with either mediaUrl or videoInfo. |
65 | | - |
66 | | -Once the module is instantiated, the following methods have to be called to monitor the playback |
67 | | -events. |
68 | | - |
69 | | -### ApiVideoPlayerAnalytics API |
70 | | - |
71 | | -#### Event time or current time |
72 | | - |
73 | | -If you know the event timestamp, you can use it as the `eventTime` parameter. If you don't know the |
74 | | -event timestamp, you can set the `currentTime` parameter with a scheduler. |
75 | | - |
76 | | -**`play(eventTime: Float = currentTime): Future<void>`** |
77 | | - |
78 | | -method to call when the video starts playing for the first time (in the case of a resume after |
| 30 | +### Code sample |
79 | 31 |
|
80 | | -paused, use `resume()`) |
| 32 | +Register the ExoPlayer player analytics agent with: |
81 | 33 |
|
82 | | -**`resume(eventTime: Float = currentTime): Future<void>`** |
| 34 | +```kotlin |
| 35 | +import androidx.media3.exoplayer.ExoPlayer |
| 36 | +import video.api.analytics.exoplayer.extensions.addDatabusAgent |
83 | 37 |
|
84 | | -method to call when the video playback is resumed after a pause |
| 38 | +val exoplayer = ExoPlayer.Builder(context).build() |
| 39 | +val listener = |
| 40 | + exoplayer.addApiVideoAnalyticsListener() // Register the ApiVideo exoplayer analytics listener so it sends player events to api.video. |
85 | 41 |
|
| 42 | +// Remove the analytics listener when you don't need it anymore. |
| 43 | +exoplayer.removeAnalyticsListener(listener) |
| 44 | +``` |
86 | 45 |
|
87 | | -**`ready(eventTime: Float = currentTime): Future<void>`** |
88 | | - |
89 | | -method to call once the player is ready to play the media |
90 | | - |
91 | | - |
92 | | -**`end(eventTime: Float = currentTime): Future<void>`** |
93 | | - |
94 | | -method to call when the video is ended |
95 | | - |
96 | | - |
97 | | -**`seek(from: Float, to: Float): Future<void>`** |
98 | | - |
99 | | -method to call when a seek event occurs, the `from` and `to` parameters are mandatory and should |
100 | | - |
101 | | -contains the seek start & end times in seconds |
102 | | - |
103 | | -**`pause(eventTime: Float = currentTime): Future<void>`** |
104 | | - |
105 | | -method to call when the video is paused |
106 | | - |
107 | | - |
108 | | -**`destroy(eventTime: Float = currentTime): Future<void>`** |
109 | | - |
110 | | -method to call when the video player is disposed (eg. when the use closes the navigation tab) |
111 | | - |
112 | | - |
113 | | -**`currentTime`** |
114 | | - |
115 | | -field to call each time the playback time changes (it should be called often, the accuracy of the |
| 46 | +For a custom domain collector, use: |
116 | 47 |
|
117 | | -collected data depends on it) if you don't know event time. |
| 48 | +```kotlin |
| 49 | +val agent = |
| 50 | + exoplayer.addDatabusAgent(collectorUrl = "https://collector.mycustomdomain.com") // Register the Databus agent so it sends player events to api.video. |
| 51 | +``` |
118 | 52 |
|
119 | | -### API documentation |
| 53 | +## FAQ |
120 | 54 |
|
121 | | -A complete [API documentation](https://apivideo.github.io/api.video-android-player-analytics/) is available. |
| 55 | +If you have any questions, ask us in the [community](https://community.api.video). |
0 commit comments