Commit 8638f2b5 authored by Martin Finkel's avatar Martin Finkel
Browse files


parent 0af12636
# ForegroundBackground sample
## Context: How it works and why
On Android, the native `libvlc` side will get released when the app gets paused/stopped (backgrounded). For LibVLCSharp users, that means you need to create a new `VideoView` and attach it to an existing, or new, `MediaPlayer` when the app goes back to foreground.
This is also true when using `LibVLCSharp.Forms`, which uses an additional abstraction layer: `Xamarin.Forms`. Since to the best of my knowledge, `Xamarin.Forms` does not provide advanced APIs to handle app lifecycle across platforms, you need to do that small plumbing yourself by using the `MessagingCenter` for example like [here](
When the app goes to background, save the `MediaPlayer` time or position and remove the `VideoView` from its parent.
When the app goes to foreground again, you will be able to reset the `MediaPlayer` position to where it stopped. Set the `MediaPlayer` on a new `VideoView` and add the view to the main layout (be it a `Grid`, `StackLayout`, etc.).
\ No newline at end of file
......@@ -12,3 +12,7 @@ A sample demonstrating how to record an HLS stream using LibVLCSharp in a .NET C
Short Xamarin.Forms sample demonstrating how to build a mosaic-style RTSP player (iOS/Android). [Blog post](
## [ForegroundBackground](
This sample demonstrates how to deal with video playback when the app goes in the background/foreground.
It shows one way to deal with this on Android with LibVLCSharp.Forms on Xamarin.Forms specifically, which is a bit trickier than other platforms.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment