Skip to content

Commit 73c6509

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents bb07311 + 97df407 commit 73c6509

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

README.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A simple library for parsing and playing links from YouTube, YouTube Music, Vime
44

55
[![Release](https://jitpack.io/v/TalbotGooday/Android-Oembed-Video.svg)](https://jitpack.io/#TalbotGooday/Android-Oembed-Video)
66

7-
# Supported Video Hostings
7+
## Supported Video Hostings
88

99
* <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/YouTube_full-color_icon_%282017%29.svg/1200px-YouTube_full-color_icon_%282017%29.svg.png" width=18px/> YouTube
1010

@@ -22,7 +22,7 @@ A simple library for parsing and playing links from YouTube, YouTube Music, Vime
2222
* <img src="https://blog.video.ibm.com/wp-content/uploads/2014/10/U_logo_blue-2.png" width=18px/> Ustream
2323
* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/ted_talks.png" width=18px/> Ted Talks
2424
* <img src="https://cdn.iconscout.com/icon/free/png-512/coub-1693601-1442642.png" width=18px/> Coub
25-
# Screenshots
25+
## Screenshots
2626

2727
<img src="/screenshots/device-2020-02-06-232720.png" width=32%/> <img src="/screenshots/device-2020-02-06-232746.png" width=32%/> <img src="/screenshots/device-2020-02-06-232924.png" width=32%/>
2828

@@ -44,7 +44,7 @@ dependencies {
4444

4545
```
4646

47-
# Work Flow
47+
## Work Flow
4848
1. Create your OkHttpClient and add it to the VideoService.Builder
4949
```kotlin
5050
val okHttpClient = OkHttpClient.Builder()
@@ -70,7 +70,7 @@ videoService.loadVideoPreview(
7070
//handle an error
7171
})
7272
```
73-
# Play Video from VideoPreviewModel
73+
## Play Video from VideoPreviewModel
7474
The BottomVideoController allows to run any oembed video in WebView.
7575
```kotlin
7676
val host = model.videoHosting
@@ -96,3 +96,51 @@ BottomVideoController.build(this) {
9696
show()
9797
}
9898
```
99+
## How to add some other video hosting
100+
1. Add the `Gson` library to your project
101+
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:
102+
```kotlin
103+
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
104+
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
105+
this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl
106+
this.videoTitle = this@UltimediaResponse.authorName
107+
this.width = this@UltimediaResponse.width.toInt()
108+
this.height = this@UltimediaResponse.height.toInt()
109+
}
110+
}
111+
```
112+
3. Create a subclass of `VideoInfoModel`, implement members and override them:
113+
```kotlin
114+
class UltimediaVideoInfoModel: VideoInfoModel<UltimediaResponse>() {
115+
override val baseUrl: String
116+
get() = "https://www.ultimedia.com"
117+
//https://regex101.com/r/2AsrOc/1
118+
override val pattern: String
119+
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*"
120+
override val idPattern: String
121+
get() = pattern //or some other another video id search pattern
122+
override val type: Class<UltimediaResponse>
123+
get() = UltimediaResponse::class.java
124+
override val hostingName: String
125+
get() = "Ultimedia"
126+
127+
override fun getInfoUrl(incomingUrl: String?): String? {
128+
return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl"
129+
}
130+
131+
override fun getPlayLink(videoId: String): String {
132+
return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/"
133+
}
134+
}
135+
```
136+
**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:
137+
```kotlin
138+
override fun parseVideoId(url: String?): String? {
139+
url ?: return null
140+
return idPattern.toRegex().find(url)?.groups?.get(**someIndex**)?.value
141+
}
142+
```
143+
## License
144+
145+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details
146+

0 commit comments

Comments
 (0)