Is it Possible to Keep WebView Audio Running in Background on Android?
Is it possible to keep audio from a WebView, in particular, an embedded Webtorrent client (which plays video), running in the background on android? I've seen conflicting answers on this, and I'm curious what you guys know about the topic. I've seen some confirmed answers on ways to do it in android studio but not seen any for Xamarin.
I've been told that the WebView is considered a UI element; therefore, this makes it impossible to keep the video/audio running while in the background. So if that's the case, do you think with some clever coding I could override the android OS to fool it into thinking that the WebView is still in the foreground?
I know that it's possible to keep the audio running using MediaPlayer, if for example say, you're playing an MP3.. So another possibility might be using a service to maintain audio focus; but then, would the video stop playing (seeing as how that doesn't fix WebView being a UI element)?
One other possibility would be porting the entire app into a service.. but I'm not sure if that's possible. If I get an answer that it is, I'll do the work to make it happen.
I'm not looking for you guys to do the coding; I'm just looking for guidance on which method (if any) would be possible/plausible/most effective.
and here is some sample code I'm currently using to construct my WebView (not sure if that matters)
//what's on
[Activity]
//this class should be an aggregate subscription feed
public class WhatsOnActivity : Activity
{
public override void OnBackPressed()
{
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.GoBack();
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.whatsOn);
//declare webview and tell our code where to find the XAML resource
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.SetBackgroundColor(Android.Graphics.Color.Green);
//set the webview client
whatsOnWebView.SetWebViewClient(new WebViewClient());
//load the 'whats on' url, will need webscript for curated subscribed feed
whatsOnWebView.LoadUrl("https://www.bitchute.com/#listing-subscribed");
//enable javascript in our webview
whatsOnWebView.Settings.JavaScriptEnabled = true;
//zoom control on? This should perhaps be disabled for consistency?
//we will leave it on for now
whatsOnWebView.Settings.BuiltInZoomControls = true;
whatsOnWebView.Settings.SetSupportZoom(true);
//scrollbarsdisabled
// subWebView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
whatsOnWebView.ScrollbarFadingEnabled = false;
}
}
EDIT: Also, my opensource project can be found here
https://github.com/hexag0d/bitchute_mobile_android_a2
Thanks, in advance. =]
c# audio xamarin.android android-webview background-process
add a comment |
Is it possible to keep audio from a WebView, in particular, an embedded Webtorrent client (which plays video), running in the background on android? I've seen conflicting answers on this, and I'm curious what you guys know about the topic. I've seen some confirmed answers on ways to do it in android studio but not seen any for Xamarin.
I've been told that the WebView is considered a UI element; therefore, this makes it impossible to keep the video/audio running while in the background. So if that's the case, do you think with some clever coding I could override the android OS to fool it into thinking that the WebView is still in the foreground?
I know that it's possible to keep the audio running using MediaPlayer, if for example say, you're playing an MP3.. So another possibility might be using a service to maintain audio focus; but then, would the video stop playing (seeing as how that doesn't fix WebView being a UI element)?
One other possibility would be porting the entire app into a service.. but I'm not sure if that's possible. If I get an answer that it is, I'll do the work to make it happen.
I'm not looking for you guys to do the coding; I'm just looking for guidance on which method (if any) would be possible/plausible/most effective.
and here is some sample code I'm currently using to construct my WebView (not sure if that matters)
//what's on
[Activity]
//this class should be an aggregate subscription feed
public class WhatsOnActivity : Activity
{
public override void OnBackPressed()
{
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.GoBack();
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.whatsOn);
//declare webview and tell our code where to find the XAML resource
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.SetBackgroundColor(Android.Graphics.Color.Green);
//set the webview client
whatsOnWebView.SetWebViewClient(new WebViewClient());
//load the 'whats on' url, will need webscript for curated subscribed feed
whatsOnWebView.LoadUrl("https://www.bitchute.com/#listing-subscribed");
//enable javascript in our webview
whatsOnWebView.Settings.JavaScriptEnabled = true;
//zoom control on? This should perhaps be disabled for consistency?
//we will leave it on for now
whatsOnWebView.Settings.BuiltInZoomControls = true;
whatsOnWebView.Settings.SetSupportZoom(true);
//scrollbarsdisabled
// subWebView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
whatsOnWebView.ScrollbarFadingEnabled = false;
}
}
EDIT: Also, my opensource project can be found here
https://github.com/hexag0d/bitchute_mobile_android_a2
Thanks, in advance. =]
c# audio xamarin.android android-webview background-process
add a comment |
Is it possible to keep audio from a WebView, in particular, an embedded Webtorrent client (which plays video), running in the background on android? I've seen conflicting answers on this, and I'm curious what you guys know about the topic. I've seen some confirmed answers on ways to do it in android studio but not seen any for Xamarin.
I've been told that the WebView is considered a UI element; therefore, this makes it impossible to keep the video/audio running while in the background. So if that's the case, do you think with some clever coding I could override the android OS to fool it into thinking that the WebView is still in the foreground?
I know that it's possible to keep the audio running using MediaPlayer, if for example say, you're playing an MP3.. So another possibility might be using a service to maintain audio focus; but then, would the video stop playing (seeing as how that doesn't fix WebView being a UI element)?
One other possibility would be porting the entire app into a service.. but I'm not sure if that's possible. If I get an answer that it is, I'll do the work to make it happen.
I'm not looking for you guys to do the coding; I'm just looking for guidance on which method (if any) would be possible/plausible/most effective.
and here is some sample code I'm currently using to construct my WebView (not sure if that matters)
//what's on
[Activity]
//this class should be an aggregate subscription feed
public class WhatsOnActivity : Activity
{
public override void OnBackPressed()
{
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.GoBack();
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.whatsOn);
//declare webview and tell our code where to find the XAML resource
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.SetBackgroundColor(Android.Graphics.Color.Green);
//set the webview client
whatsOnWebView.SetWebViewClient(new WebViewClient());
//load the 'whats on' url, will need webscript for curated subscribed feed
whatsOnWebView.LoadUrl("https://www.bitchute.com/#listing-subscribed");
//enable javascript in our webview
whatsOnWebView.Settings.JavaScriptEnabled = true;
//zoom control on? This should perhaps be disabled for consistency?
//we will leave it on for now
whatsOnWebView.Settings.BuiltInZoomControls = true;
whatsOnWebView.Settings.SetSupportZoom(true);
//scrollbarsdisabled
// subWebView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
whatsOnWebView.ScrollbarFadingEnabled = false;
}
}
EDIT: Also, my opensource project can be found here
https://github.com/hexag0d/bitchute_mobile_android_a2
Thanks, in advance. =]
c# audio xamarin.android android-webview background-process
Is it possible to keep audio from a WebView, in particular, an embedded Webtorrent client (which plays video), running in the background on android? I've seen conflicting answers on this, and I'm curious what you guys know about the topic. I've seen some confirmed answers on ways to do it in android studio but not seen any for Xamarin.
I've been told that the WebView is considered a UI element; therefore, this makes it impossible to keep the video/audio running while in the background. So if that's the case, do you think with some clever coding I could override the android OS to fool it into thinking that the WebView is still in the foreground?
I know that it's possible to keep the audio running using MediaPlayer, if for example say, you're playing an MP3.. So another possibility might be using a service to maintain audio focus; but then, would the video stop playing (seeing as how that doesn't fix WebView being a UI element)?
One other possibility would be porting the entire app into a service.. but I'm not sure if that's possible. If I get an answer that it is, I'll do the work to make it happen.
I'm not looking for you guys to do the coding; I'm just looking for guidance on which method (if any) would be possible/plausible/most effective.
and here is some sample code I'm currently using to construct my WebView (not sure if that matters)
//what's on
[Activity]
//this class should be an aggregate subscription feed
public class WhatsOnActivity : Activity
{
public override void OnBackPressed()
{
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.GoBack();
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.whatsOn);
//declare webview and tell our code where to find the XAML resource
WebView whatsOnWebView = FindViewById<WebView>(Resource.Id.webViewWhatsOn);
whatsOnWebView.SetBackgroundColor(Android.Graphics.Color.Green);
//set the webview client
whatsOnWebView.SetWebViewClient(new WebViewClient());
//load the 'whats on' url, will need webscript for curated subscribed feed
whatsOnWebView.LoadUrl("https://www.bitchute.com/#listing-subscribed");
//enable javascript in our webview
whatsOnWebView.Settings.JavaScriptEnabled = true;
//zoom control on? This should perhaps be disabled for consistency?
//we will leave it on for now
whatsOnWebView.Settings.BuiltInZoomControls = true;
whatsOnWebView.Settings.SetSupportZoom(true);
//scrollbarsdisabled
// subWebView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
whatsOnWebView.ScrollbarFadingEnabled = false;
}
}
EDIT: Also, my opensource project can be found here
https://github.com/hexag0d/bitchute_mobile_android_a2
Thanks, in advance. =]
c# audio xamarin.android android-webview background-process
c# audio xamarin.android android-webview background-process
asked Nov 24 '18 at 17:27
hexagodhexagod
65
65
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460667%2fis-it-possible-to-keep-webview-audio-running-in-background-on-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460667%2fis-it-possible-to-keep-webview-audio-running-in-background-on-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown