├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── libs │ └── YouTubeAndroidPlayerApi.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── echessa │ │ └── videotube │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── echessa │ │ │ └── videotube │ │ │ ├── Config.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── echessa │ └── videotube │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.echessa.videotube" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.1.0' 28 | testCompile 'junit:junit:4.12' 29 | 30 | compile files('libs/YouTubeAndroidPlayerApi.jar') 31 | } 32 | -------------------------------------------------------------------------------- /app/libs/YouTubeAndroidPlayerApi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sitepoint-editors/Android-VideoTube/a8c14d9dd53a84b2837da67e7c90007901c3dc1e/app/libs/YouTubeAndroidPlayerApi.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/echessa/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/echessa/videotube/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.echessa.videotube; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.echessa.videotube", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/echessa/videotube/Config.java: -------------------------------------------------------------------------------- 1 | package com.echessa.videotube; 2 | 3 | /** 4 | * Created by echessa on 1/13/17. 5 | */ 6 | 7 | public final class Config { 8 | 9 | private Config() { 10 | } 11 | 12 | public static final String YOUTUBE_API_KEY = "AIzaSyCG25IwSEZcJuF5Te7kko9XawkHaEJ48Ws"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/echessa/videotube/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.echessa.videotube; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.EditText; 8 | import android.widget.Toast; 9 | 10 | import com.google.android.youtube.player.YouTubeBaseActivity; 11 | import com.google.android.youtube.player.YouTubeInitializationResult; 12 | import com.google.android.youtube.player.YouTubePlayer; 13 | import com.google.android.youtube.player.YouTubePlayer.Provider; 14 | import com.google.android.youtube.player.YouTubePlayerView; 15 | 16 | public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener { 17 | 18 | private static final int RECOVERY_REQUEST = 1; 19 | private YouTubePlayerView youTubeView; 20 | private MyPlayerStateChangeListener playerStateChangeListener; 21 | private MyPlaybackEventListener playbackEventListener; 22 | private YouTubePlayer player; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main); 28 | 29 | youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view); 30 | youTubeView.initialize(Config.YOUTUBE_API_KEY, this); 31 | 32 | playerStateChangeListener = new MyPlayerStateChangeListener(); 33 | playbackEventListener = new MyPlaybackEventListener(); 34 | 35 | final EditText seekToText = (EditText) findViewById(R.id.seek_to_text); 36 | Button seekToButton = (Button) findViewById(R.id.seek_to_button); 37 | seekToButton.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | int skipToSecs = Integer.valueOf(seekToText.getText().toString()); 41 | player.seekToMillis(skipToSecs * 1000); 42 | } 43 | }); 44 | } 45 | 46 | @Override 47 | public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) { 48 | this.player = player; 49 | player.setPlayerStateChangeListener(playerStateChangeListener); 50 | player.setPlaybackEventListener(playbackEventListener); 51 | 52 | if (!wasRestored) { 53 | player.cueVideo("fhWaJi1Hsfo"); // Plays https://www.youtube.com/watch?v=fhWaJi1Hsfo 54 | } 55 | } 56 | 57 | @Override 58 | public void onInitializationFailure(Provider provider, YouTubeInitializationResult errorReason) { 59 | if (errorReason.isUserRecoverableError()) { 60 | errorReason.getErrorDialog(this, RECOVERY_REQUEST).show(); 61 | } else { 62 | String error = String.format(getString(R.string.player_error), errorReason.toString()); 63 | Toast.makeText(this, error, Toast.LENGTH_LONG).show(); 64 | } 65 | } 66 | 67 | @Override 68 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 69 | if (requestCode == RECOVERY_REQUEST) { 70 | // Retry initialization if user performed a recovery action 71 | getYouTubePlayerProvider().initialize(Config.YOUTUBE_API_KEY, this); 72 | } 73 | } 74 | 75 | protected Provider getYouTubePlayerProvider() { 76 | return youTubeView; 77 | } 78 | 79 | private void showMessage(String message) { 80 | Toast.makeText(this, message, Toast.LENGTH_LONG).show(); 81 | } 82 | 83 | private final class MyPlaybackEventListener implements YouTubePlayer.PlaybackEventListener { 84 | 85 | @Override 86 | public void onPlaying() { 87 | // Called when playback starts, either due to user action or call to play(). 88 | showMessage("Playing"); 89 | } 90 | 91 | @Override 92 | public void onPaused() { 93 | // Called when playback is paused, either due to user action or call to pause(). 94 | showMessage("Paused"); 95 | } 96 | 97 | @Override 98 | public void onStopped() { 99 | // Called when playback stops for a reason other than being paused. 100 | showMessage("Stopped"); 101 | } 102 | 103 | @Override 104 | public void onBuffering(boolean b) { 105 | // Called when buffering starts or ends. 106 | } 107 | 108 | @Override 109 | public void onSeekTo(int i) { 110 | // Called when a jump in playback position occurs, either 111 | // due to user scrubbing or call to seekRelativeMillis() or seekToMillis() 112 | } 113 | } 114 | 115 | private final class MyPlayerStateChangeListener implements YouTubePlayer.PlayerStateChangeListener { 116 | 117 | @Override 118 | public void onLoading() { 119 | // Called when the player is loading a video 120 | // At this point, it's not ready to accept commands affecting playback such as play() or pause() 121 | } 122 | 123 | @Override 124 | public void onLoaded(String s) { 125 | // Called when a video is done loading. 126 | // Playback methods such as play(), pause() or seekToMillis(int) may be called after this callback. 127 | } 128 | 129 | @Override 130 | public void onAdStarted() { 131 | // Called when playback of an advertisement starts. 132 | } 133 | 134 | @Override 135 | public void onVideoStarted() { 136 | // Called when playback of the video starts. 137 | } 138 | 139 | @Override 140 | public void onVideoEnded() { 141 | // Called when the video reaches its end. 142 | } 143 | 144 | @Override 145 | public void onError(YouTubePlayer.ErrorReason errorReason) { 146 | // Called when an error occurs. 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 17 | 18 | 24 | 25 |