Video SDK for Android
The Eagle Eye Networks Video Android SDK is a library that shows Eagle Eye Networks playbacks via ExoPlayer.
Installation
1- Go to [Your Profile] => [Developer settings] => [Personal access token] => [Generate a new token] on github.com
2- Check “read: packages”
3- Click “Generate token”
4- Copy the generated token
5- Add the below lines to your “~/.gradle/gradle.properties”
GITHUB_ID={your github id}
GITHUB_PACKAGES_TOKEN={the generated token}
6- Merge the below lines to your “/settings.gradle” (If you are using the recent version of the Android Gradle Plugin)
dependencyResolutionManagement {
repositories {
maven {
url "https://maven.pkg.github.com/EENCloud/VMS-Developer-Portal"
credentials {
username GITHUB_ID
password GITHUB_PACKAGES_TOKEN
}
}
}
}
Alternately add to your “/build.gradle”
dependencies {
implementation 'com.een:een-video-android-sdk:1.0.0'
}
In the case that GitHub packages are not working for you or you don’t want to use them, you can download the aar file directly from the GitHub packages page (URL). The aar file is under the Assets section.
You can check the newest version of the library here.
Proguard
If you’re using R8 add following lines to your proguard-rules.pro:
-keep class com.een.player_sdk.model.** { *; }
EENMediaPlayer
First step to use SDK is to add EENMediaPlayer to your layout xml:
<com.een.player_sdk.EENMediaPlayer
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Available attributes:
Name | Format | Description |
backgroundColor | color | Sets background color for the player. |
showPlayStopAnimation | boolean | True -> shows play and stop image animation when user stop playback or resume playback |
showBuffering | boolean | If true then we show progress bar when the playback buffering |
progressBarIndeterminateTint | color | Color of progress bar shown when playback is buffering |
progressBarIndeterminateDrawable | reference (drawable) | Drawable of progress bar shown when playback is buffering |
EENMediaItem
In order to initialize EENMediaPlayer you need to use EENMediaItem. To initialize this object you need to have at least a URL of preview, other parameters are optional.
data class EENMediaItem(
private var _url: String,// playback url
private val authToken: String? = null, //access token (will be added to url)
)
Initialization
To Initialize the EENMediaPlayer you need to create an EENMediaItem and pass it to the player with the init(...) method. Also, you should release a player when you don’t need it anymore.
override fun onStart() {
super.onStart()
args?.let {
binding.player.init(
EENMediaItem.Live(
url = it.urls[0],
authToken = NetworkManager.tokenV3
)
)
binding.player.play()
}
override fun onStop() {
super.onStop()
binding.player.release()
}
Protocols
Right now we support these protocols:
Video | Live |
MP4 | RTSP |
FLV | FLV |
State handling
You can observe player state changes by creating a PlayerStateListener object and passing it to the EENMediaPlayer class via the playerStateListener field. (You can also use ExoPlayer Listener by adding it to ExoPlayer player which you can access via EENMediaPlayer)
PlayerStateListener:
interface PlayerStateListener {
/**
* The player has finished playing the media.
*/
fun onEnd(){}
/**
* The player is idle, meaning it holds only limited resources. The player must be prepared before it will play the media.
*/
fun onIdle(){}
/**
* The player is not able to immediately play the media, but is doing work toward being able to do so.
* This state typically occurs when the player needs to buffer more data before playback can start.
*/
fun onBuffering(){}
/**
* The player is able to immediately play from its current position.
* The player will be playing if getPlayWhenReady() is true, and paused otherwise.
*/
fun onReady(){}
/**
* Called when the value of isPlaying() changes.
* @param - isPlaying – Whether the player is playing.
*/
fun onIsPlayingChanged(isPlaying: Boolean) { }
/**
* Called when the exception occurs
* @param error - wrapper for ExoPlayer PlaybackException
* @see [PlaybackException](https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/PlaybackException.html")
* @see [ExoPlaybackException](https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ExoPlaybackException.html")
*/
fun onError(error: PlayerExceptionWrapper){}
}
Interfaces
EENVideoPlayer:
interface EENVideoPlayer {
/**
* Returns ExoPlayer Player object if is initialized, otherwise return null
*/
val player : Player?
/**
* Returns current position of playback, if the player is not initialized return null
*/
val currentPosition: Long?
/**
* Callback for player state changes like onBuffering, onError, etc. @see [PlayerStateListener]
*/
var playerStateListener : PlayerStateListener?
/**
* Callback for surface click. By default on click it's stopping or resuming playback in a case we are showing a video
*/
var onSurfaceClick : View.OnClickListener?
/**
* Initializing and preparing ExoPlayer to play playback
* @param item - stream data (url, auth token, eagleEyeCameraConfig) @see [EENMediaItem]
* @param errorPolicy - we can pass custom error policy, if we don't pass it we are using default ExoPlayer error policy
*/
fun init(item: EENMediaItem, errorPolicy: EenDefaultLoadErrorHandlingPolicy = EenDefaultLoadErrorHandlingPolicy())
/**
* Changing preview source to new one
* @param url - url of new source, other parameters are the same as we provided in init
*/
fun changeUrl(url: String)
/**
* Play playback
*/
fun play()
/**
* Pause playback
*/
fun pause()
/**
* Informs player that we want to get snapshot, the result is provided by listener
* @param listener - listener for snapshot
*/
fun getSnapshot(listener: SnapshotListener)
/**
* Release player, video processor and timer. This method must be called when the player is no longer required.
* The player must not be used after calling this method.
* To be able to use player again after using this method we need to call init(...) again
*/
fun release()
}
EENPlayerAudio:
interface EENPlayerAudio {
/**
* Gets the current volume of the device.
* Sets the volume of the device.
* Is null if player is not initialized
*/
var audioVolume : Float?
/**
* Gets whether the device is muted or not.
* Sets the mute state of the device.
* Is null if player is not initialized
*/
var audioMuted : Boolean?
}
EENPlayerTimer:
interface EENPlayerTimer {
/**
* Attaching timer to player. Timer is publicising position of player every 100ms. Need to be attached before playback start playing!
* @param listener – timer listener @see TimerListener
*/
fun attachTimer(listener: TimerListener)
}
Updated over 1 year ago