Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #5

Merged
merged 17 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '12'
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '12'
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '12'
java-version: '17'
distribution: 'adopt'
- name: Make gradlew executable
run: chmod +x ./gradlew
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '12'
java-version: '17'
distribution: 'adopt'
- name: Make gradlew executable
run: chmod +x ./gradlew
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '12'
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ your app.
- [Installation](#installation)
- [Gradle](#gradle)
- [Retrieve your video Id](#retrieve-your-video-id)
- [Usage](#usage)
- [View-based usage](#view-based-usage)
- [Supported player views](#supported-player-views)
- [Jetpack Compose usage](#jetpack-compose-usage)
- [Play your api.video video with ExoPlayer, MediaPlayer and VideoView](#play-your-apivideo-video-with-exoplayer-mediaplayer-and-videoview)
- [Sample application](#sample-application)
- [Documentation](#documentation)
Expand All @@ -27,6 +28,8 @@ your app.

Easily integrate a video player for videos from [api.video](https://api.video) in your Android
application.
The api.video Android player will help you to play the HLS video from api.video. It also generates
analytics of [your viewers usage](https://api.video/product/video-analytics/).

# Getting started

Expand All @@ -42,6 +45,14 @@ dependencies {
}
```

For Jetpack Compose, also add the following code in `dependencies`:

```groovy
dependencies {
implementation 'video.api:android-compose-player:1.4.2'
}
```

## Retrieve your video Id

At this point, you must have uploaded a least one video to your account. If you haven't
Expand All @@ -63,21 +74,20 @@ a video Id to use this component and play a video from api.video. To get yours,
Alternatively, you can find your video Id in the video details of
your [dashboard](https://dashboard.api.video).

## Usage
## View-based usage

The api.video Android player will help you to play the HLS video from api.video. It also generates
analytics of [your viewers usage](https://api.video/product/video-analytics/).
The api.video Android player comes with a view `ApiVideoExoPlayerView` to display the video and its
controller `ApiVideoPlayerController`.

1. Add a `ApiVideoExoPlayerView` to your Activity/Fragment layout:

```xml

<video.api.player.ApiVideoExoPlayerView
<video.api.player.ApiVideoExoPlayerView
android:id="@+id/playerView"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:show_fullscreen_button="true"
app:show_controls="true"
app:show_controls="true"
app:show_subtitles="true" />
```

Expand All @@ -102,7 +112,7 @@ val playerControllerListener = object : ApiVideoPlayerController.Listener {
```kotlin
val playerView = findViewById<ApiVideoExoPlayerView>(R.id.playerView)

val player = ApiVideoPlayerController(
val playerController = ApiVideoPlayerController(
applicationContext,
VideoOptions(
"YOUR_VIDEO_ID",
Expand All @@ -115,8 +125,20 @@ val player = ApiVideoPlayerController(

4. Fullscreen video

If you requires a fullscreen video. You will have to implement
the `ApiVideoPlayerController.ViewListener` interface.
If you require a fullscreen video. You will have to implement
the `ApiVideoExoPlayerView.FullScreenListener` interface.
To help you, you can use the `ApiVideoPlayerFullScreenController` that will handle the fullscreen.
As it implements the `ApiVideoExoPlayerView.FullScreenListener` interface, you can pass it to
your `ApiVideoExoPlayerView` instance.

```kotlin
playerView.fullScreenListener = ApiVideoExoPlayerView(
supportFragmentManager,
playerView,
playerController
)
```

Check out for the implementation in the [Sample application](#sample-application).

### Supported player views
Expand All @@ -134,6 +156,17 @@ Otherwise, in the `ApiVideoPlayerController`, you can also use the following vie

The `SurfaceView` and the `Surface` require more work to be used.

## Jetpack compose usage

The api.video Android player comes with a composable `ApiVideoPlayer` to display the video from a
compose application. In your application, you can add:

```kotlin
ApiVideoPlayer(
videoOptions = VideoOptions("YOUR_VIDEO_ID", VideoType.VOD),
)
```

## Play your api.video video with ExoPlayer, MediaPlayer and VideoView

If you want to use the ExoPlayer directly, you can use the api.video Android extensions:
Expand Down Expand Up @@ -173,7 +206,7 @@ videoView.setVideo(videoOptions)
# Sample application

A demo application demonstrates how to use player.
See [`/example`](https://github.com/apivideo/api.video-android-player/tree/main/example)
See [`/examples`](https://github.com/apivideo/api.video-android-player/tree/main/examples)
folder.

On the first run, you will have to set your video Id:
Expand Down
27 changes: 19 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ buildscript {
targetSdk = 34

// Kotlin
kotlinVersion = "1.8.22"
dokkaVersion = "1.8.20"
kotlinVersion = "1.9.10"
dokkaVersion = "1.9.10"

// Example
versionCode = properties['VERSION_CODE'].toInteger()
Expand All @@ -18,17 +18,28 @@ buildscript {
exoPlayerVersion = '1.1.1'
analyticsVersion = '2.0.2'
}

dependencies {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
}
}
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVersion" apply false
id 'org.jetbrains.dokka' version "$dokkaVersion"
}

tasks.register('clean', Delete) {
delete rootProject.buildDir
}

tasks.dokkaHtmlMultiModule {
moduleName.set("api.video Android $project.name library")
suppressInheritedMembers.set(true)

pluginsMapConfiguration.set(
["org.jetbrains.dokka.base.DokkaBase": """{
"customAssets" : [
"${file("$rootDir/docs/docs_logo.svg")}",
"${file("$rootDir/docs/logo-icon.svg")}"
]
}"""]
)
}
42 changes: 42 additions & 0 deletions common_library.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
android {
defaultConfig {
minSdk rootProject.minSdk
targetSdk rootProject.targetSdk
compileSdk rootProject.compileSdk

consumerProguardFiles 'proguard-rules.txt'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

buildFeatures {
viewBinding true
}

kotlinOptions {
jvmTarget = '1.8'
}

testOptions {
unitTests.returnDefaultValues = true
}
}

dokkaHtmlPartial {
dokkaSourceSets {
named("main") {
noAndroidSdkLink.set(false)
skipDeprecated.set(true)
includeNonPublic.set(false)
skipEmptyPackages.set(true)
}
}
}
File renamed without changes.
49 changes: 49 additions & 0 deletions compose-player/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.dokka'
}
apply from: "${project.rootDir}/common_library.gradle"
apply from: "${project.rootDir}/publish.gradle"

ext {
artifactName = 'android-compose-player'
artifactDescription = 'Android Jetpack compose player for api.video delivery.'
}

android {
namespace 'video.api.compose.player'

buildFeatures {
compose true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.5.3"
}
}

dependencies {
def composeBom = platform('androidx.compose:compose-bom:2023.10.00')
implementation(composeBom)
androidTestImplementation(composeBom)

api project(path: ':player')

implementation 'androidx.core:core-ktx:1.12.0'
implementation "androidx.compose.ui:ui"
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.material3:material3-window-size-class:1.1.2'
implementation "androidx.compose.material:material-icons-extended"
implementation "androidx.compose.ui:ui-tooling-preview"

implementation "androidx.media3:media3-ui:${exoPlayerVersion}"
implementation "androidx.media3:media3-exoplayer:${exoPlayerVersion}"
implementation "androidx.media:media:1.6.0"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4"
debugImplementation "androidx.compose.ui:ui-tooling"
}
Empty file.
File renamed without changes.
8 changes: 8 additions & 0 deletions compose-player/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<!--This permission is required to use the ExoPlayer for Android >= 33-->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

</manifest>
Loading