Notification when sound starts in webview - xamarin.android

I'm developing a web-based radio player app. When the radio plays in webview I want to send a notification. How can i do this?
the webview codes:
webview = FindViewById(Resource.Id.webView1);
webview.SetWebViewClient(new ExtendWebClient());
webview.LoadUrl("http://www.jantiradyo.net/radio/app.php");
WebSettings webSet = webview.Settings;
webSet.JavaScriptEnabled = true;

Related

iOS How to trigger video to keep playing after exiting fullscreen?

I'm building a website that plays video in iOS. I have a fullscreen button working in iOS however the video pauses when exiting fullscreen. Does anyone know a way to either force the video to continue to play upon exiting fullscreen or how to set up a listener that triggers the video to autoplay upon exiting fullscreen?
here is my code:
<script>
var video = document.getElementById('tv'),
play = document.getElementById('fullscreenbutton'),
time;
video.addEventListener('webkitbeginfullscreen', function() {
play.innerText = '';
window.clearInterval(time);
});
video.addEventListener('webkitendfullscreen', function() {
tv.autoplay();
});
play.addEventListener('touchstart', function() {
time = window.setInterval(function() {
try {
video.webkitEnterFullscreen();
}
catch(e) {}
}, 250);
play.innerText = 'loading ...';
tv.play();
});
</script>
'''
You can use WKScriptMessageHandler in your iOS app when a button to exit fullscreen mode is tapped then resume your video player.
Here is a workaround on how I would handle this situation.
Native iOS + JavaScript
1 Step: Website front end part
When exit full screen button is tapped on your website emit an event give it a unique name something like "exitFullScreenEvent"
2 Step: iOS App
import WebKit
ViewController: WKScriptMessageHandler {
// Helper method to set configurations for your webView in iOS
func configureWebView() {
///Add the script message handler into the content controller.
let contentController = WKUserContentController()
/// Give it the same name as on the web front-end part
contentController.add(self, name: "exitFullScreenEvent")
let config = WKWebViewConfiguration()
config.userContentController = contentController
/// Most important, when initilizing your web view pass the configuration above
let webView = WKWebView(frame: .zero, configuration: config)
// Layout/add constraints to your webView
// .....
}
// Delegate method to listen an event emitted from your website
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
// TODO: - Resume/ Play your video
}
}
Pure Website (Javascript only)
For website only which runs in pure Javascript without any iOS related components and on Safari browser you might want to check this webkitjs displayingfullscreen
I Haven't used it before but it worth reading the doc.
But another work around without putting lots of effort is to compare your video player's screen size with the browsers window size ie.. check if browser is full screen if so get the full screen width if it's the same with your video player's size then video is in full screen.

After CallKit integration video call app ends the call if power button is pressed

After integrating callkit into video call app pressing the power button is ending the call when the call is in progress
Below is the provider configuration:
static var providerConfiguration: CXProviderConfiguration {
let providerConfiguration = CXProviderConfiguration(localizedName: "AppName")
providerConfiguration.supportsVideo = true
providerConfiguration.maximumCallsPerCallGroup = 1
providerConfiguration.supportedHandleTypes = [.phoneNumber]
return providerConfiguration
}
below is CXCallUpdate to report that there is an incoming call:
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: handle)
update.supportsDTMF = true;
update.hasVideo = hasVideo;
update.supportsGrouping = false;
update.supportsUngrouping = false;
update.supportsHolding = false;
If we see cisco webex video call, there also callkit has been integrated, but for video call pressing the power button is not ending the call when call is in progress. But pressing the power button is ending the call for audio call. I observed the same behaviour with WhatsApp video call as well.
This is the intended behaviour: if try to do the same thing with the iOS built-in phone app, you'll obtain the same result.
EDIT
The power button ends a call if and only if the call is running through the built-in speaker on top of the screen. In any other case (i.e. the audio is playing through headphones, bluetooth or built-in loudspeaker) the power button will not end the call.

AvPlayer and AirPlay not working quite well

I am coding a video player with Xamarin, AVPlayer and AvPlayerViewController. My code supports AirPlay and configures AVPlayer according docs but is not working quite well. The following scenario seems to fail:
Play a video, send it to Apple TV.
Exit playback as it goes on the Apple TV
Try to resume playback from the current position. This leads to playback directly starting on the Apple TV but the seek which I do to resume from the last playback position kind of fails. What happens is that AvPlayerViewController UI shows that playback starts from the beginning while the Apple TV is playing back from the resume point. The AvPlayerViewController play/pause button is also wrong most of the time and is not reflecting the right play state.
I do the seek so I resume the video like this: wait ( by KVO ) for the avplayer status to become ready to play, seek and then play the video.
Note ... all this works just fine when player is not in airplay mode. Video resumes properly and UI is looking correct.
Code looks like this:
avItem = new AVPlayerItem(avAsset);
avPlayer = new AVPlayer(avItem)
{
AllowsExternalPlayback = true,
UsesExternalPlaybackWhileExternalScreenIsActive = true
};
avPlayerViewController = new AVPlayerViewController()
{
View =
{
ContentMode = UIViewContentMode.ScaleAspectFill,
AutoresizingMask = UIViewAutoresizing.All,
},
UpdatesNowPlayingInfoCenter = false,
Player = avPlayer
};
initialPlaybackTime = TimeSpan.FromSeconds(bookmarkTime);
AddChildViewController(avPlayerViewController);
View.AddSubview(avPlayerViewController.View);
avPlayerViewController.DidMoveToParentViewController(this);
avItem.AddObserver(this, new NSString("status"), NSKeyValueObservingOptions.Initial, IntPtr.Zero);
public override async void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
if (Equals(ofObject, avItem) && keyPath.Equals((NSString)"status"))
{
if (!initialPlaybackTimeSet && (avPlayer.Status == AVPlayerStatus.ReadyToPlay))
{
await avPlayer.SeekAsync(CMTime.FromSeconds(initialPlaybackTime.TotalSeconds, avPlayer.CurrentItem.Asset.Duration.TimeScale));
avPlayer.Play();
initialPlaybackTimeSet = true;
}
}
}

WKWebView stop audio when backgrounding app

I have a WKWebView which is playing HTML5 video. When I click the home button and the app enters the background I can still hear the audio playing. How can I pause the HTML 5 video to stop the background audio from playing. I tried just loading a blank page when the app enters background which works,
let url = URL(string: "about:blank")
let request = URLRequest(url:url!)
self.webView.load(request)
but I want to be able to start the video at the same point when the user returns from the background so it is not a viable solution since it just loads the blank page when I open the app back up.
I was able to achive this by injecting JavaScript when the app entered the background which would pause any video elements that are playing.
NotificationCenter.default.addObserver(self, selector: #selector(enteredBackground(notification:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
#objc func enteredBackground(notification: Notification) {
let script = "var vids = document.getElementsByTagName('video'); for( var i = 0; i < vids.length; i++ ){vids.item(i).pause()}"
self.webView.evaluateJavaScript(script, completionHandler:nil)
}

show audio or video controller in dart

I want to create a audio or video controller, but my current code only plays the content, nothing is shown to control it in my browser
#import ('dart:html');
void main () {
AudioElement audio = new AudioElement();
audio.src="http://slides.html5rocks.com/src/rushus-modal_blues.mp3";
audio.autoplay=true;
window.document.body.nodes.add(audio);
}
So how do you get Dart to show a controller for audio/video ?
The controls for audio/video are disabled by default. You will need to enable them
audio.controls = true;
should do the trick.
Alternativly you can also build the audio source and controls settings from scractch, the following examples shows this and have been tested sucessfully with dart2js
var audioSource = new SourceElement();
audioSource.src = "http://slides.html5rocks.com/src/rushus-modal_blues.mp3";
audioSource.type = "audio/mp3";
var audio = new AudioElement();
audio.attributes["controls"] = "controls";
audio.nodes.add(audioSource);
window.document.body.nodes.add(audio);
There is more info on controlling audio here and video here

Resources