Skip to content

Commit

Permalink
Finish: embedded video in-app play. Pending to solve the status bar p…
Browse files Browse the repository at this point in the history
…roblem.
  • Loading branch information
absolutelycold committed Feb 29, 2020
1 parent 9646616 commit b9658b7
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 14 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,4 @@ Finished:

✔ Collect favorite videos in the local database (本地收藏夹)

Not Finished Yet:

✖ Show embedded video in the WebView (在WebView中显示嵌入视频)

✖ <del>Watch/Download videos (If someone provide me java library for capturing the m3u8 video from video page)</del> **I know this option may break the rules of the Avgle, so if someone provide me such a library, I will not publish it. However, I will do it in another branch.**
✔ watch full video(在WebView中显示嵌入视频)
23 changes: 17 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.absolutelycold.axgle">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -10,20 +11,30 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_avgle_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ShowUserCollectionActivity"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true">
<activity
android:name=".EmbedVideoActivity"
android:screenOrientation="sensorLandscape"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ShowUserCollectionActivity"
android:label="My Collection"
android:screenOrientation="portrait"
android:label="My Collection"></activity>
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".SearchResultActivity"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ShowVideoPreviewActivity"
android:parentActivityName=".MainActivity"
android:screenOrientation="landscape" />
android:screenOrientation="sensorLandscape"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
65 changes: 65 additions & 0 deletions app/src/main/java/com/absolutelycold/axgle/EmbedVideoActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.absolutelycold.axgle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import java.util.HashMap;

public class EmbedVideoActivity extends AppCompatActivity {

private String embeddedUrl;
private WebView webView;
private View decorView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_embed_video);
Intent intent = getIntent();
embeddedUrl = intent.getStringExtra("embeddedUrl");

String frameVideo = "<iframe width=\"100%\" height=\"100%\" src=\"" + embeddedUrl + "\" frameborder=\"0\" allowfullscreen></iframe>";

getSupportActionBar().hide();
decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
decorView.setBackgroundColor(Color.BLACK);

webView = findViewById(R.id.embed_video_web_view);
webView.setBackgroundColor(Color.TRANSPARENT);


webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
//webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setDomStorageEnabled(true);
webView.loadDataWithBaseURL("https://absolutelycold.github.io", frameVideo, "text/html", null, null);
//webView.loadDataWithBaseURL(null, frameVideo, "text/html", "utf-8", null);
//webView.loadUrl(embeddedUrl, extraHeader);
}

@Override
protected void onPostResume() {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
super.onPostResume();
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
decorView.setBackgroundColor(Color.BLACK);

if (savedInstanceState != null) {
this.previewVideoUrl = savedInstanceState.getString("preview_video_url");
this.embeddedUrl = savedInstanceState.getString("embedded_url");
Expand Down Expand Up @@ -79,7 +80,6 @@ public void onClick(View view) {
}
});
videoView = findViewById(R.id.video_preview);

//System.out.println("Play Url: " + previewVideoUrl);

}
Expand Down Expand Up @@ -120,8 +120,8 @@ public void onSortOptionSelected(int position) {
orderDialogFragment.dismiss();
break;
case 1:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(embeddedUrl));
Intent intent = new Intent(this, EmbedVideoActivity.class);
intent.putExtra("embeddedUrl", embeddedUrl);
startActivity(intent);
break;
case 2:
Expand All @@ -142,4 +142,12 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString("video_url", videoUrl);
outState.putString("embedded_url", embeddedUrl);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}


}
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_embed_video.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EmbedVideoActivity">

<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/embed_video_web_view"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit b9658b7

Please sign in to comment.