Skip to content

Commit 16bbfe7

Browse files
2 parents 4766102 + 2845c14 commit 16bbfe7

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

README.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,73 @@
11
# inline-youtube-view
22

3-
YouTube component for Android, iOS and React
3+
YouTube component for Android, iOS and React. This is a suite of utility libraries around using YouTube inside your Android, iOS or React Native app.
44

5-
**Doc will be updated soon**
5+
# youtube-android
6+
7+
Playing Youtube on Android (specially inline) comes with some challenges :
8+
- YouTube SDK does not work on all devices ( where YouTube services could have been uninstalled)
9+
- You cannot run more than one instance of the YouTube view
10+
- Playing them inline where in a list you can have more than one videos in a single list.
11+
12+
inline-youtube-view for Android checks if the services are available and will fall back gracefully to using WebView in the event they are not.
13+
14+
YouTubePlayerView : The YouTubePlayerView provided by the YouTube SDK comes with a restriction that the activty hosting this needs to extend from YouTubeBaseActivity. This view removes these restrictions.
15+
16+
## Demo Gifs
17+
18+
### YouTubePlayer in Activity (Fullscreen Mode)
19+
20+
![YouTube Activity](https://github.com/flipkart-incubator/inline-youtube-view/blob/master/youtube-activity-android.gif)
21+
22+
### YouTubePlayer in Fragment (inline native)
23+
24+
![YouTube Fragment](https://github.com/flipkart-incubator/inline-youtube-view/blob/master/youtube-fragment-android.gif)
25+
26+
## How to use ?
27+
28+
Add it in your root build.gradle at the end of repositories :
29+
30+
````java
31+
allprojects {
32+
repositories {
33+
...
34+
maven { url "https://jitpack.io" }
35+
}
36+
}
37+
````
38+
39+
Add the dependency
40+
41+
````java
42+
dependencies {
43+
//to be updated soon.
44+
}
45+
````
46+
47+
### YouTubePlayer Activity
48+
49+
Start an YouTubeActivity intent with apiKey and videoId. This will play the youtube video in a new activity in fullscreen mode.
50+
51+
````java
52+
Intent intent = new Intent(MainActivity.this, YouTubeActivity.class);
53+
intent.putExtra("apiKey", Constants.API_KEY);
54+
intent.putExtra("videoId", "3AtDnEC4zak");
55+
startActivity(intent);
56+
````
57+
58+
### YouTubePlayer Inline
59+
60+
Create an instance of YouTubePlayerView inside a fragment. To initialize the player, you need to call the initPlayer method with following params:
61+
1. apiKey
62+
2. videoId
63+
3. webviewUrl : the link to iframe.html file (this is required when the device is not able to render native video, a fallback). By default, use 'https://cdn.rawgit.com/flipkart-incubator/inline-youtube-view/60bae1a1/youtube-android/youtube_iframe_player.html'
64+
4. playerType : native, webview or auto (try native, else fallback to webview)
65+
5. listener : callback listener
66+
6. fragment : fragment hosting this view
67+
7. imageLoader : to load thumbnail image
68+
69+
````java
70+
YouTubePlayerView playerView = new YouTubePlayerView(context);
71+
playerView.initPlayer(Constants.API_KEY, videoId, "https://cdn.rawgit.com/flipkart-incubator/inline-youtube-view/60bae1a1/youtube-android/youtube_iframe_player.html", playerType, listener, fragment, imageLoader);
72+
73+
````

youtube-activity-android.gif

6.57 MB
Loading

youtube-fragment-android.gif

8.66 MB
Loading

0 commit comments

Comments
 (0)