-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.example.my_video" | ||
minSdkVersion 19 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.2.1' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.my_video; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.example.my_video", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.my_video"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.My_Video"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package com.example.my_video; | ||
|
||
import android.media.MediaPlayer; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.webkit.URLUtil; | ||
import android.widget.MediaController; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
import android.widget.VideoView; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private static final String VIDEO_SAMPLE = "vid1"; | ||
private VideoView mVideoView; | ||
private TextView mBufferingTextView; | ||
|
||
private int mCurrentPosition = 0; | ||
private static final String PLAYBACK_TIME = "play_time"; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
mVideoView = findViewById(R.id.videoview); | ||
mBufferingTextView = findViewById(R.id.buffering_textview); | ||
|
||
if (savedInstanceState != null) { | ||
mCurrentPosition = savedInstanceState.getInt(PLAYBACK_TIME); | ||
} | ||
|
||
MediaController controller = new MediaController(this); | ||
controller.setMediaPlayer(mVideoView); | ||
mVideoView.setMediaController(controller); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
|
||
initializePlayer(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
|
||
releasePlayer(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
|
||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | ||
mVideoView.pause(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
|
||
outState.putInt(PLAYBACK_TIME, mVideoView.getCurrentPosition()); | ||
} | ||
|
||
private void initializePlayer() { | ||
mBufferingTextView.setVisibility(VideoView.VISIBLE); | ||
Uri videoUri = getMedia(VIDEO_SAMPLE); | ||
mVideoView.setVideoURI(videoUri); | ||
|
||
// if (mCurrentPosition > 0) { | ||
// mVideoView.seekTo(mCurrentPosition); | ||
// } else { | ||
// // Skipping to 1 shows the first frame of the video. | ||
// mVideoView.seekTo(1); | ||
// } | ||
|
||
|
||
|
||
mVideoView.setOnPreparedListener( | ||
new MediaPlayer.OnPreparedListener() { | ||
@Override | ||
public void onPrepared(MediaPlayer mediaPlayer) { | ||
mBufferingTextView.setVisibility(VideoView.INVISIBLE); | ||
|
||
if (mCurrentPosition > 0) { | ||
mVideoView.seekTo(mCurrentPosition); | ||
} else { | ||
mVideoView.seekTo(1); | ||
} | ||
|
||
mVideoView.start(); | ||
} | ||
}); | ||
|
||
//mVideoView.start(); | ||
|
||
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { | ||
@Override | ||
public void onCompletion(MediaPlayer mediaPlayer) { | ||
Toast.makeText(MainActivity.this, "Playback completed", | ||
Toast.LENGTH_SHORT).show(); | ||
mVideoView.seekTo(1); | ||
} | ||
}); | ||
} | ||
private void releasePlayer() { | ||
mVideoView.stopPlayback(); | ||
} | ||
private Uri getMedia(String mediaName) { | ||
if (URLUtil.isValidUrl(mediaName)) { | ||
// media name is an external URL | ||
return Uri.parse(mediaName); | ||
} else { // media name is a raw resource embedded in the app | ||
return Uri.parse("android.resource://" + getPackageName() + | ||
"/raw/" + mediaName); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108" | ||
android:tint="#E23233"> | ||
<group android:scaleX="2.61" | ||
android:scaleY="2.61" | ||
android:translateX="22.68" | ||
android:translateY="22.68"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/> | ||
</group> | ||
</vector> |