Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TalbotGooday/Android-Oembed-Video
A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube in the WebView without the need to connect API data services
https://github.com/TalbotGooday/Android-Oembed-Video
android android-ui custom oembed video video-hosting view
Last synced: 9 days ago
JSON representation
A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube in the WebView without the need to connect API data services
- Host: GitHub
- URL: https://github.com/TalbotGooday/Android-Oembed-Video
- Owner: TalbotGooday
- License: apache-2.0
- Created: 2019-12-03T14:35:18.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-25T20:47:42.000Z (8 months ago)
- Last Synced: 2024-08-01T19:44:51.099Z (4 months ago)
- Topics: android, android-ui, custom, oembed, video, video-hosting, view
- Language: Kotlin
- Homepage:
- Size: 4.67 MB
- Stars: 39
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - TalbotGooday/Android-Oembed-Video - A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube in the WebView without the need to connect API data services (Kotlin)
README
# Android Oembed Video
A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube and others in the WebView without the need to connect data API services.[![Release](https://jitpack.io/v/TalbotGooday/Android-Oembed-Video.svg)](https://jitpack.io/#TalbotGooday/Android-Oembed-Video) [![Platform](https://img.shields.io/badge/platforms-Android-green.svg)]() [![Languages](https://img.shields.io/badge/languages-Kotlin-F18E33.svg)]()
## Supported Video Hostings
* YouTube
* YouTube Music
* Vimeo
* Rutube
* Facebook (is no longer available due to API restrictions)
* Dailymotion
* Wistia
* ~~Vzaar~~ (it's Dacast now)
* Hulu
* Ustream
* Ted Talks
* Coub
* Streamable
* Loom## Screenshots
Add it in your root build.gradle at the end of repositories:
```java
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add the dependency```java
dependencies {
implementation 'com.github.TalbotGooday:Android-Oembed-Video:Tag'
}```
## Work Flow
1. Create your OkHttpClient and add it to the VideoService.Builder
```kotlin
val okHttpClient = OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.build()val videoService = VideoService.build{
with(this@MainActivity)
httpClient(okHttpClient)
enableCache(true)
enableLog(true)
}
```
2. Get VideoPreviewModel
```kotlin
videoService.loadVideoPreview(
url,
onSuccess = { video ->
//handle a video model
},
onError = { url, error ->
//handle an error
})
```
3. Enable/disable caching
```kotlin
val videoService = VideoService.build {
enableCache(true)
}
```
4. Enable/disable logging
```kotlin
val videoService = VideoService.build {
enableLog(BuildConfig.DEBUG)
}
```
## Play Video from VideoPreviewModel
The BottomVideoController allows to run any oembed video in WebView.
```kotlin
val host = model.videoHosting
val linkToPlay = model.linkToPlay
val title = model.videoTitle
val initUrl = model.urlBottomVideoController.build(this) {
setListener(object : BottomVideoController.Listener() {
override fun openLinkIn(link: String) {
openLink(link)
}
override fun copyLink(link: String) {
copyLinkToClipboard(link)
}
})
setHostText(host)
setPlayLink(linkToPlay)
setSize(model.width, model.height)
setTitle(title)
setVideoUrl(initUrl)
setProgressView(TextView(this@MainActivity).apply { text = "Loading" })
show()
}
```
## How to add some other video hosting
1. Add the `Gson` library to your project
2. Create the `Gson` data class from the embed response of the video service. Make this class a subclass of `VideoInfoModel`, implement the` toPreview` function, and override it:
```kotlin
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
this.thumbnailUrl = [email protected]
this.videoTitle = [email protected]
this.width = [email protected]()
this.height = [email protected]()
}
}
```
3. Create a subclass of `VideoInfoModel`, implement members and override them:
```kotlin
class UltimediaVideoInfoModel: VideoInfoModel() {
override val baseUrl: String
get() = "https://www.ultimedia.com"
//https://regex101.com/r/2AsrOc/1
override val pattern: String
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*"
override val idPattern: String
get() = pattern //or some another video id search pattern
override val type: Class
get() = UltimediaResponse::class.java
override val hostingName: String
get() = "Ultimedia"override fun getInfoUrl(incomingUrl: String?): String? {
return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl"
}override fun getPlayLink(videoId: String): String {
return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/"
}
}
```
**Note:** By default, the index of the `Regex` group should be **1**. If your `idPattern` does not fulfill this condition, then override the `parseVideoId` method:
```kotlin
override fun parseVideoId(url: String?): String? {
url ?: return null
return idPattern.toRegex().find(url)?.groups?.get(**someIndex**)?.value
}
```
## LicenseThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details