Skip to content

Commit 6dd9e09

Browse files
authored
Merge pull request #1 from gitzain/videoactivity
Core video player implemented
2 parents bd08e28 + 8d83d9b commit 6dd9e09

File tree

7 files changed

+160
-6
lines changed

7 files changed

+160
-6
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ dependencies {
2424
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})
27-
compile 'com.android.support:appcompat-v7:25.3.1'
28-
compile 'com.android.support.constraint:constraint-layout:1.0.2'
29-
testCompile 'junit:junit:4.12'
3027

3128
compile('com.mikepenz:materialdrawer:5.9.1@aar') {
3229
transitive = true
3330
}
34-
compile 'com.jakewharton:butterknife:6.1.0'
3531

32+
compile 'com.android.support:appcompat-v7:25.3.1'
33+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
34+
compile 'com.jakewharton:butterknife:6.1.0'
35+
testCompile 'junit:junit:4.12'
3636
}

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package="com.iamzain.template_android"
44
android:versionName="@string/version">
55

6+
<uses-permission android:name="android.permission.INTERNET" />
7+
68
<application
79
android:allowBackup="true"
810
android:icon="@mipmap/ic_launcher"
@@ -15,6 +17,7 @@
1517
android:theme="@style/AppTheme.BrandedLaunch">
1618
<intent-filter>
1719
<action android:name="android.intent.action.MAIN" />
20+
1821
<category android:name="android.intent.category.LAUNCHER" />
1922
</intent-filter>
2023
</activity>
@@ -24,6 +27,9 @@
2427
android:theme="@style/AppTheme" />
2528
<activity android:name=".AboutActivity" />
2629
<activity android:name=".SettingsActivity" />
30+
<activity android:name=".VideoActivity"
31+
android:configChanges="orientation|screenSize">
32+
</activity>
2733
</application>
2834

2935
</manifest>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.iamzain.template_android;
2+
3+
import android.content.res.Configuration;
4+
import android.graphics.Color;
5+
import android.net.Uri;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.os.Bundle;
8+
import android.support.v7.widget.Toolbar;
9+
import android.view.View;
10+
import android.view.WindowManager;
11+
import android.widget.MediaController;
12+
import android.widget.VideoView;
13+
14+
import static com.iamzain.template_android.R.id.videoView;
15+
16+
public class VideoActivity extends AppCompatActivity {
17+
18+
private Toolbar toolbar;
19+
private String video;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_video);
25+
createToolbar();
26+
playVideo();
27+
getWindow().setStatusBarColor(Color.BLACK);
28+
}
29+
30+
private void createToolbar()
31+
{
32+
toolbar = (Toolbar) findViewById(R.id.toolbar);
33+
setSupportActionBar(toolbar);
34+
getSupportActionBar().setTitle("");
35+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
36+
getSupportActionBar().setDisplayShowHomeEnabled(true);
37+
}
38+
39+
public void playVideo() {
40+
// create video player
41+
VideoView videoview = (VideoView) findViewById(videoView);
42+
Uri uri = Uri.parse("https://d1swr4916zvh4g.cloudfront.net/media/bbb-360p.mp4");
43+
videoview.setVideoURI(uri);
44+
45+
// create and set video controls
46+
MediaController mediaController = new MediaController(this);
47+
mediaController.setAnchorView(videoview);
48+
videoview.setMediaController(mediaController);
49+
50+
videoview.start();
51+
}
52+
53+
@Override
54+
public void onConfigurationChanged(Configuration newConfig) {
55+
super.onConfigurationChanged(newConfig);
56+
57+
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
58+
{
59+
hideSystemUI();
60+
}
61+
else
62+
{
63+
showSystemUI();
64+
}
65+
}
66+
67+
private void hideSystemUI() {
68+
View decorView = getWindow().getDecorView();
69+
70+
decorView.setSystemUiVisibility(
71+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
72+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
73+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
74+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
75+
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
76+
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
77+
78+
toolbar.setVisibility(View.GONE);
79+
}
80+
81+
private void showSystemUI() {
82+
View decorView = getWindow().getDecorView();
83+
84+
decorView.setSystemUiVisibility(
85+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
86+
87+
toolbar.setVisibility(View.VISIBLE);
88+
}
89+
90+
@Override
91+
public void onWindowFocusChanged(boolean hasFocus) {
92+
super.onWindowFocusChanged(hasFocus);
93+
94+
View decorView = getWindow().getDecorView();
95+
96+
if (hasFocus) {
97+
98+
99+
int orientation=this.getResources().getConfiguration().orientation;
100+
if(orientation==Configuration.ORIENTATION_LANDSCAPE){
101+
//code for portrait mode
102+
hideSystemUI();
103+
}
104+
else{
105+
//code for landscape mode
106+
showSystemUI();
107+
}
108+
}
109+
110+
}
111+
112+
@Override
113+
public boolean onSupportNavigateUp() {
114+
onBackPressed();
115+
return true;
116+
}
117+
118+
119+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:background="#000"
7+
tools:context="com.iamzain.template_android.VideoActivity">
8+
9+
<android.support.v7.widget.Toolbar
10+
android:id="@+id/toolbar"
11+
android:layout_width="match_parent"
12+
android:layout_height="?attr/actionBarSize"
13+
android:background="@android:color/transparent"
14+
android:elevation="4dp"
15+
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
16+
17+
<VideoView
18+
android:id="@+id/videoView"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent"
21+
android:layout_gravity="center"/>
22+
23+
</FrameLayout>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.3.1'
8+
classpath 'com.android.tools.build:gradle:2.3.2'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files

0 commit comments

Comments
 (0)