-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new 'Settings' menu item - offers 3 options to configure how video URLs will be watched: * internal video player w/ Chromecast sender - default option - same behavior as previous app versions * uses ExoPlayer to watch video url - all HTTP requests include the referer url * when the video url is cast to Chromecast - the referer url is ignored, because Chromecast receiver apps aren't allowed to change this HTTP request header * external video player - starts an implicit Intent * allows any app with a matching Intent filter to take over * only includes the video url (data) and mime-type (type) * ExoAirPlayer sender - works with the receiver app: github.com/warren-bank/Android-ExoPlayer-AirPlay-Receiver - loads the URL in a WebView: 'http://webcast-reloaded.surge.sh/airplay_sender.html' + `#/watch/${base64_video}/referer/${base64_referer}` - this page prepopulates the form fields from URL hash: * video url * referer url - this page prepopulates the form fields from previous use: * host * port * https - this page provides a basic UI to control any receiver app that is reachable through the network caveats * when using the 'ExoAirPlayer sender' - the page that loads in a WebView uses modern javascript * this is incompatible with very old web browsers, such as the native WebView in Android prior to 5.0 * this issue will be addressed in a future release
- Loading branch information
1 parent
2c2471c
commit 980d87a
Showing
11 changed files
with
392 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
...Cast/src/main/java/com/github/warren_bank/webcast/webview/ExoAirPlayerSenderActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package com.github.warren_bank.webcast.webview; | ||
|
||
import com.github.warren_bank.webcast.R; | ||
|
||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
import android.webkit.CookieManager; | ||
import android.webkit.WebSettings; | ||
import android.webkit.WebViewClient; | ||
import android.webkit.WebView; | ||
import android.webkit.WebResourceRequest; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
public class ExoAirPlayerSenderActivity extends AppCompatActivity { | ||
private static final String AIRPLAY_SENDER = "http://webcast-reloaded.surge.sh/airplay_sender.html"; | ||
|
||
private String page_domain; | ||
private String page_path; | ||
private String page_url; | ||
private WebView webView; | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
// Lifecycle Events: | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
getPageUrl(); | ||
if (page_url == null) | ||
finish(); | ||
|
||
setContentView(R.layout.exoairplayer_sender_activity); | ||
webView = (WebView)findViewById(R.id.webView); | ||
initWebView(); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
|
||
restoreCookies(); | ||
webView.loadUrl(page_url); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
super.onStop(); | ||
|
||
saveCookies(); | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
// Intent: | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
private void getPageUrl() { | ||
Uri page = Uri.parse(AIRPLAY_SENDER); | ||
Intent intent = getIntent(); | ||
String video = intent.getStringExtra("video"); | ||
String referer = intent.getStringExtra("referer"); | ||
|
||
page_domain = page.getHost(); | ||
page_path = page.getPath(); | ||
page_url = (video == null) | ||
? null | ||
: ( | ||
AIRPLAY_SENDER + | ||
"#/watch/" + | ||
BrowserUtils.base64_encode(video) + | ||
((referer == null) | ||
? "" | ||
: ( | ||
"/referer/" + | ||
BrowserUtils.base64_encode(referer) | ||
) | ||
) | ||
) | ||
; | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
// WebView: | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
private void initWebView() { | ||
webView.setWebViewClient(new WebViewClient(){ | ||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView view, String url) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { | ||
return true; | ||
} | ||
}); | ||
|
||
WebSettings webSettings = webView.getSettings(); | ||
webSettings.setLoadWithOverviewMode(true); | ||
webSettings.setSupportZoom(true); | ||
webSettings.setBuiltInZoomControls(true); | ||
webSettings.setDisplayZoomControls(true); | ||
webSettings.setUseWideViewPort(false); | ||
webSettings.setJavaScriptEnabled(true); | ||
webSettings.setDomStorageEnabled(false); | ||
webSettings.setUserAgentString( | ||
getResources().getString(R.string.user_agent) | ||
); | ||
if (Build.VERSION.SDK_INT >= 21) { | ||
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); | ||
} | ||
|
||
webView.setInitialScale(0); | ||
webView.setHorizontalScrollBarEnabled(false); | ||
webView.setVerticalScrollBarEnabled(false); | ||
} | ||
|
||
private void restoreCookies() { | ||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | ||
String pref_key = getString(R.string.pref_persistentcookies_key); | ||
String cookies = prefs.getString(pref_key, null); | ||
|
||
if (cookies != null) { | ||
String[] cookiesArr = cookies.split("\\s*;\\s+"); | ||
CookieManager CM = CookieManager.getInstance(); | ||
String cookie; | ||
|
||
for (int i=0; i < cookiesArr.length; i++) { | ||
cookie = cookiesArr[i] + "; Domain=" + page_domain + "; Path=" + page_path; | ||
CM.setCookie(AIRPLAY_SENDER, cookie); | ||
} | ||
} | ||
} | ||
|
||
private void saveCookies() { | ||
String cookies = CookieManager.getInstance().getCookie(AIRPLAY_SENDER); | ||
|
||
if (cookies != null) { | ||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | ||
SharedPreferences.Editor editor = prefs.edit(); | ||
String pref_key = getString(R.string.pref_persistentcookies_key); | ||
|
||
editor.putString(pref_key, cookies); | ||
editor.commit(); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...roject/WebCast/src/main/java/com/github/warren_bank/webcast/webview/SettingsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.warren_bank.webcast.webview; | ||
|
||
import android.os.Bundle; | ||
import android.preference.PreferenceActivity; | ||
|
||
public class SettingsActivity extends PreferenceActivity { | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit(); | ||
} | ||
} |
Oops, something went wrong.