Skip to content

Commit ab9c7f3

Browse files
author
TheFinestArtist
committed
Update 1.2.0
1 parent 3de607b commit ab9c7f3

File tree

14 files changed

+217
-103
lines changed

14 files changed

+217
-103
lines changed

README.md

+29-22
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Easily reference the library in your Android projects using this dependency in y
4040

4141
```Gradle
4242
dependencies {
43-
compile 'com.thefinestartist:ytpa:1.1.1'
43+
compile 'com.thefinestartist:ytpa:1.2.0'
4444
}
4545
```
4646

@@ -51,30 +51,22 @@ It supports Android API 7+.
5151

5252
## Features
5353
* Orientation Support
54-
55-
AUTO
56-
57-
AUTO_START_WITH_LANDSCAPE
58-
59-
ONLY_LANDSCAPE
60-
61-
ONLY_PORTRAIT
54+
* AUTO
55+
* AUTO_START_WITH_LANDSCAPE
56+
* ONLY_LANDSCAPE
57+
* ONLY_PORTRAIT
6258

6359
* Media Volume Support
64-
65-
While watching YouTube Player, users should be able to set media volume!!!
60+
* While watching YouTube Player, users should be able to set media volume!!!
6661

6762
* Video Play Error Support
68-
69-
If the video is not playable, it send to youtube app or other browser which will might play it.
63+
* If the video is not playable, it send to youtube app or other browser which will might play it.
7064

7165
* Animation Support
72-
73-
Activity closing animation can be customized.
66+
* Activity closing animation can be customized.
7467

7568
* Status Bar Support
76-
77-
On screen portrait mode, it removed status bar automatically.
69+
* On screen portrait mode, it removed status bar automatically.
7870

7971

8072
## Set Up AndroidManifest.xml
@@ -97,9 +89,8 @@ It supports Android API 7+.
9789
```java
9890
Intent intent = new Intent(MainActivity.this, YouTubePlayerActivity.class);
9991

100-
// Youtube video ID or Url (Required)
92+
// Youtube video ID (Required, You can use YouTubeUrlParser to parse Video Id from url)
10193
intent.putExtra(YouTubePlayerActivity.EXTRA_VIDEO_ID, "iS1g8G_njx8");
102-
intent.putExtra(YouTubePlayerActivity.EXTRA_VIDEO_URL, "https://youtu.be/iS1g8G_njx8");
10394

10495
// Youtube player style (DEFAULT as default)
10596
intent.putExtra(YouTubePlayerActivity.EXTRA_PLAYER_STYLE, YouTubePlayer.PlayerStyle.DEFAULT);
@@ -123,13 +114,29 @@ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
123114
startActivity(intent);
124115
```
125116

126-
## YoutubeUrlParser
117+
## YouTubeUrlParser
127118

128119
This util helps to retrieve youtube video id from youtube url or vice versa. [Reference](https://gist.github.com/afeld/1254889)
129120

130121
```java
131-
String vidoeId = YoutubeUrlParser.getVideoId(videoUrl);
132-
String vidoeUrl = YoutubeUrlParser.getVideoId(videoId);
122+
String vidoeId = YouTubeUrlParser.getVideoId(videoUrl);
123+
String vidoeUrl = YouTubeUrlParser.getVideoUrl(videoId);
124+
```
125+
126+
## YouTubeApp
127+
128+
This util helps to open Youtube App and play specific video.
129+
130+
```java
131+
YouTubeApp.startVideo(context, videoId);
132+
```
133+
134+
## YouTubeThumbnail
135+
136+
This util returns Youtube thumbnail image url.
137+
138+
```java
139+
YouTubeThumbnail.getUrlFromVideoId(videoId, Quality.HIGH);
133140
```
134141

135142

library/build.gradle

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ android {
55
compileSdkVersion 22
66
buildToolsVersion "22.0.1"
77

8+
compileOptions {
9+
sourceCompatibility JavaVersion.VERSION_1_7
10+
targetCompatibility JavaVersion.VERSION_1_7
11+
}
12+
813
defaultConfig {
914
minSdkVersion 7
1015
targetSdkVersion 22
11-
versionCode 2
12-
versionName "1.1.1"
16+
versionCode 3
17+
versionName "1.2.0"
1318
}
1419
lintOptions {
1520
abortOnError false
@@ -18,14 +23,14 @@ android {
1823

1924
dependencies {
2025
compile fileTree(dir: 'libs', include: ['*.jar'])
21-
compile 'com.android.support:appcompat-v7:22.0.+'
26+
compile 'com.android.support:support-annotations:22.+'
2227
}
2328

2429
publish {
2530
userOrg = 'thefinestartist'
2631
groupId = 'com.thefinestartist'
2732
artifactId = 'ytpa'
28-
version = '1.1.1'
33+
version = '1.2.0'
2934
description = 'Simply pass a url to play youtube video in new activity. It supports screen orientation, media volume control and etc.'
3035
website = 'https://github.com/TheFinestArtist/YouTubePlayerActivity'
3136
}

library/src/main/java/com/thefinestartist/ytpa/YouTubePlayerActivity.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.content.res.Configuration;
99
import android.os.Build;
1010
import android.os.Bundle;
11+
import android.support.annotation.NonNull;
1112
import android.util.Log;
1213
import android.view.KeyEvent;
1314
import android.widget.FrameLayout.LayoutParams;
@@ -21,8 +22,7 @@
2122
import com.thefinestartist.ytpa.enums.Orientation;
2223
import com.thefinestartist.ytpa.utils.AudioUtil;
2324
import com.thefinestartist.ytpa.utils.StatusBarUtil;
24-
import com.thefinestartist.ytpa.utils.YouTubeUrlParser;
25-
import com.thefinestartist.ytpa.utils.YouTubeUtil;
25+
import com.thefinestartist.ytpa.utils.YouTubeApp;
2626

2727
public class YouTubePlayerActivity extends YouTubeBaseActivity implements
2828
YouTubePlayer.OnInitializedListener,
@@ -31,10 +31,9 @@ public class YouTubePlayerActivity extends YouTubeBaseActivity implements
3131

3232
private static final int RECOVERY_DIALOG_REQUEST = 1;
3333

34-
public static final String META_DATA_NAME = "com.thefinestartist.ytpa.YouTubePlayerActivity.ApiKey";
34+
private static final String META_DATA_NAME = "com.thefinestartist.ytpa.YouTubePlayerActivity.ApiKey";
3535

3636
public static final String EXTRA_VIDEO_ID = "video_id";
37-
public static final String EXTRA_VIDEO_URL = "video_url";
3837

3938
public static final String EXTRA_PLAYER_STYLE = "player_style";
4039

@@ -88,13 +87,7 @@ private void initialize() {
8887
if (googleApiKey == null)
8988
throw new NullPointerException("Google API key must not be null. Set your api key as meta data in AndroidManifest.xml file.");
9089

91-
String videoUrl = getIntent().getStringExtra(EXTRA_VIDEO_URL);
92-
if (videoUrl != null)
93-
videoId = YouTubeUrlParser.getVideoId(videoUrl);
94-
95-
if (videoId == null)
96-
videoId = getIntent().getStringExtra(EXTRA_VIDEO_ID);
97-
90+
videoId = getIntent().getStringExtra(EXTRA_VIDEO_ID);
9891
if (videoId == null)
9992
throw new NullPointerException("Video ID must not be null");
10093

@@ -238,7 +231,7 @@ public void onFullscreen(boolean fullScreen) {
238231
public void onError(ErrorReason reason) {
239232
Log.e("onError", "onError : " + reason.name());
240233
if (handleError && ErrorReason.NOT_PLAYABLE.equals(reason))
241-
YouTubeUtil.startVideo(this, videoId);
234+
YouTubeApp.startVideo(this, videoId);
242235
}
243236

244237
@Override
@@ -264,7 +257,7 @@ public void onVideoStarted() {
264257

265258
// Audio Managing
266259
@Override
267-
public boolean onKeyDown(int keyCode, KeyEvent event) {
260+
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
268261
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
269262
AudioUtil.adjustMusicVolume(getApplicationContext(), true, showAudioUi);
270263
StatusBarUtil.hide(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.thefinestartist.ytpa.enums;
2+
3+
/**
4+
* Created by TheFinestArtist on 6/27/15.
5+
*/
6+
public enum Quality {
7+
FIRST, SECOND, THIRD, FOURTH, MAXIMUM, STANDARD_DEFINITION, MEDIUM, HIGH, DEFAULT
8+
}

library/src/main/java/com/thefinestartist/ytpa/utils/YoutubeUtil.java library/src/main/java/com/thefinestartist/ytpa/utils/YouTubeApp.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
import android.content.pm.PackageManager;
66
import android.content.pm.ResolveInfo;
77
import android.net.Uri;
8+
import android.support.annotation.NonNull;
89

910
import java.util.List;
1011

1112
/**
1213
* Created by TheFinestArtist on 2/16/15.
1314
*/
14-
public class YouTubeUtil {
15+
public class YouTubeApp {
1516

16-
public static void startVideo(Context context, String videoId) {
17-
if (context == null || videoId == null)
18-
return;
19-
20-
Uri video_uri = Uri.parse(YouTubeUrlParser.getVidoeUrl(videoId));
17+
public static void startVideo(@NonNull Context context, @NonNull String videoId) {
18+
Uri video_uri = Uri.parse(YouTubeUrlParser.getVideoUrl(videoId));
2119
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId));
2220
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(
2321
intent,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.thefinestartist.ytpa.utils;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.thefinestartist.ytpa.enums.Quality;
6+
7+
/**
8+
* Created by TheFinestArtist on 6/27/15.
9+
*/
10+
public class YouTubeThumbnail {
11+
// Each YouTube video has 4 generated images. They are predictably formatted as follows:
12+
//
13+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
14+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
15+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
16+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
17+
//
18+
// The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of `1.jpg`, `2.jpg`, `3.jpg`) is:
19+
//
20+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
21+
//
22+
// For the high quality version of the thumbnail use a url similar to this:
23+
//
24+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
25+
//
26+
// There is also a medium quality version of the thumbnail, using a url similar to the HQ:
27+
//
28+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
29+
//
30+
// For the standard definition version of the thumbnail, use a url similar to this:
31+
//
32+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
33+
//
34+
// For the maximum resolution version of the thumbnail use a url similar to this:
35+
//
36+
// http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
37+
//
38+
// All of the above urls are available over https too. Just change `http` to `https` in any of the above urls. Additionally, the slightly shorter hostname `i3.ytimg.com` works in place of `img.youtube.com` in the example urls above.
39+
//
40+
// Alternatively, you can use the [YouTube Data API (v3)][1] or the older [YouTube API v2.0][2] to get thumbnail images.
41+
//
42+
//
43+
// [1]: https://developers.google.com/youtube/v3/
44+
// [2]: http://code.google.com/apis/youtube/2.0/developers_guide_php.html
45+
46+
public static String getUrlFromVideoId(@NonNull String videoId, @NonNull Quality quality) {
47+
switch (quality) {
48+
case FIRST:
49+
return "http://img.youtube.com/vi/" + videoId + "/0.jpg";
50+
case SECOND:
51+
return "http://img.youtube.com/vi/" + videoId + "/1.jpg";
52+
case THIRD:
53+
return "http://img.youtube.com/vi/" + videoId + "/2.jpg";
54+
case FOURTH:
55+
return "http://img.youtube.com/vi/" + videoId + "/3.jpg";
56+
case MAXIMUM:
57+
return "http://img.youtube.com/vi/" + videoId + "/maxresdefault.jpg";
58+
case STANDARD_DEFINITION:
59+
return "http://img.youtube.com/vi/" + videoId + "/sddefault.jpg";
60+
case MEDIUM:
61+
return "http://img.youtube.com/vi/" + videoId + "/mqdefault.jpg";
62+
case HIGH:
63+
return "http://img.youtube.com/vi/" + videoId + "/hqdefault.jpg";
64+
case DEFAULT:
65+
default:
66+
return "http://img.youtube.com/vi/" + videoId + "/default.jpg";
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.thefinestartist.ytpa.utils;
22

3+
import android.support.annotation.NonNull;
4+
35
import java.util.regex.Matcher;
46
import java.util.regex.Pattern;
57

@@ -11,10 +13,7 @@ public class YouTubeUrlParser {
1113
// (?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})
1214
final static String reg = "(?:youtube(?:-nocookie)?\\.com\\/(?:[^\\/\\n\\s]+\\/\\S+\\/|(?:v|e(?:mbed)?)\\/|\\S*?[?&]v=)|youtu\\.be\\/)([a-zA-Z0-9_-]{11})";
1315

14-
public static String getVideoId(String videoUrl) {
15-
if (videoUrl == null || videoUrl.trim().length() <= 0)
16-
return null;
17-
16+
public static String getVideoId(@NonNull String videoUrl) {
1817
Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
1918
Matcher matcher = pattern.matcher(videoUrl);
2019

@@ -23,7 +22,7 @@ public static String getVideoId(String videoUrl) {
2322
return null;
2423
}
2524

26-
public static String getVidoeUrl(String videoId) {
25+
public static String getVideoUrl(@NonNull String videoId) {
2726
return "http://youtu.be/" + videoId;
2827
}
2928
}

sample/build.gradle

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
buildscript {
22
repositories {
3-
maven { url 'http://download.crashlytics.com/maven' }
3+
maven { url 'https://maven.fabric.io/public' }
44
}
55

66
dependencies {
7-
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
7+
classpath 'io.fabric.tools:gradle:1.+'
88
}
99
}
1010
apply plugin: 'com.android.application'
11-
apply plugin: 'crashlytics'
11+
apply plugin: 'io.fabric'
1212

1313
repositories {
14-
maven { url 'http://download.crashlytics.com/maven' }
14+
maven { url 'https://maven.fabric.io/public' }
1515
}
1616

1717

1818
android {
1919
compileSdkVersion 22
2020
buildToolsVersion "22.0.1"
2121

22+
compileOptions {
23+
sourceCompatibility JavaVersion.VERSION_1_7
24+
targetCompatibility JavaVersion.VERSION_1_7
25+
}
26+
2227
defaultConfig {
2328
applicationId "com.thefinestartist.ytpa.sample"
24-
minSdkVersion 8
29+
minSdkVersion 9
2530
targetSdkVersion 22
26-
versionCode 5
27-
versionName "1.4.0"
31+
versionCode 6
32+
versionName "1.5.0"
2833
}
2934
buildTypes {
3035
release {
@@ -38,7 +43,11 @@ dependencies {
3843
compile fileTree(dir: 'libs', include: ['*.jar'])
3944
compile project(':library')
4045
compile 'com.android.support:appcompat-v7:22.0.+'
41-
compile 'com.jakewharton:butterknife:5.1.2'
46+
compile 'com.jakewharton:butterknife:6.+'
4247
compile 'com.afollestad:material-dialogs:0.7.3.+'
43-
compile 'com.crashlytics.android:crashlytics:1.+'
48+
compile 'com.google.android.gms:play-services-ads:7.+'
49+
compile 'com.squareup.picasso:picasso:2.+'
50+
compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
51+
transitive = true;
52+
}
4453
}

sample/fabric.properties

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public.
2+
#Sat Jun 27 18:03:28 KST 2015
3+
apiSecret=ed8e20e7d4101d02885f3a2839ee4d5f9045819d88301d58f8e88d734f3d603e

sample/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
<meta-data
3434
android:name="com.crashlytics.ApiKey"
3535
android:value="286eb9845a463270ba6a058f160c64043f7639e9" />
36-
</application>
3736

37+
</application>
3838
</manifest>

0 commit comments

Comments
 (0)