Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.AAkira:ExoPlayerManager:'
}
dependencies {
implementation("com.github.AAkira:ExoPlayerManager:")
}
<dependency>
<groupId>com.github.AAkira</groupId>
<artifactId>ExoPlayerManager</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.AAkira" % "ExoPlayerManager" % ""
:dependencies [[com.github.AAkira/ExoPlayerManager ""]]
An android library that wraps the ExoPlayer and the IMA Android SDK which plays a video advertisement.
This is written in Kotlin.
// inject from xml
val playerView: PlayerView by bindView(R.id.playerView)
val playerManager: ExoPlayerManager = ExoPlayerManager.Builder(context).run {
build(
renderersFactory = createRenderersFactory(), // You can set your RenderersFactory
loadControl = createDefaultLoadControl( // You can set your LoadControl
minBufferMs = 15000,
maxBufferMs = 50000,
bufferForPlaybackMs = 2500,
bufferForPlaybackAfterRebufferMs = 5000
),
drmSessionManager = null // You can set your drmSessionManager
)
}
// inject PlayerView
playerManager.injectView(playerView)
val dataSource = DataSourceCreator.UrlBuilder(
url = HLS_SAMPLE_URL,
userAgent = Util.getUserAgent(this, "UserAgent"),
okHttpClient = your ok http client, // you can use your okhttp client if you want use it.
dataSourceCreatorInterface = your data source // you can use your data source if you want use it.
)
playerManager.setHlsSource(dataSource.build())
// play
playerManager.play()
// pause
playerManager.pause()
// stop
playerManager.stop()
// release
playerManager.release()
// mute
playerManager.toMute()
// limit bitrate
playerManager.setMaxVideoBitrate((60 * 1000).toLong())
// change playback speed (speed, pitch)
playerManager.setPlaybackParameters(2f, 2f)
// state listener
playerManager.addOnStateChangedListener { playWhenReady: Boolean, playbackState: Int ->
}
// error listener
playerManager.addOnPlayerErrorListener {
}
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
app:surface_type="texture_view"
app:use_controller="false" />
</RelativeLayout>
val adPlayerController: AdPlayerController = AdPlayerController.Builder(
context = this,
playerView = playerView,
adUiContainer = adUiContainer,
language = "us",
userAgent = Util.getUserAgent(this, "UserAgent"),
playerManager = playerManager)
.create()
// call in Activity onResume()
adPlayerController.resume()
// call in Activity onPause()
adPlayerController.pause()
// call in Activity onDestroy()
adPlayerController.destroy()
// call in Activity detachedFromWindow()
adPlayerController.release()
Add the dependency in your build.gradle
buildscript {
repositories {
jcenter()
}
}
dependencies {
implementation 'com.github.aakira:exoplayer-manager:0.13.0@aar'
implementation 'com.github.aakira:exoplayer-manager-ima:0.13.0@aar' // if you use an IMA SDK
}
reference : exoplayer-textureview
Copyright (C) 2017 A.Akira
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.