You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.9 KiB
145 lines
4.9 KiB
using Flurl;
|
|
using LibVLCSharp.Shared;
|
|
using System;
|
|
using System.Net.Http;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Xaml;
|
|
|
|
namespace Demo
|
|
{
|
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
|
public partial class OnvifPage : ContentPage
|
|
{
|
|
private readonly string _url;
|
|
private readonly LibVLC _libvlc;
|
|
|
|
public OnvifPage(string url)
|
|
{
|
|
this._url = url;
|
|
InitializeComponent();
|
|
NavigationPage.SetHasNavigationBar(this, false);
|
|
Core.Initialize();
|
|
this._libvlc = new LibVLC();
|
|
if (url.IndexOf("ptz") != -1)
|
|
{
|
|
this.left.Source = SetImage("left.png");
|
|
this.right.Source = SetImage("right.png");
|
|
this.up.Source = SetImage("up.png");
|
|
this.down.Source = SetImage("down.png");
|
|
this.zoomin.Source = SetImage("zoomin.png");
|
|
this.zoomout.Source = SetImage("zoomout.png");
|
|
}
|
|
else
|
|
{
|
|
this.left.IsEnabled = false;
|
|
this.right.IsEnabled = false;
|
|
this.up.IsEnabled = false;
|
|
this.down.IsEnabled = false;
|
|
this.zoomin.IsEnabled = false;
|
|
this.zoomout.IsEnabled = false;
|
|
}
|
|
this.back.Source = SetImage("back.png");
|
|
this.mute.Source = SetImage("mute.png");
|
|
this.volume.Value = 0;
|
|
}
|
|
|
|
protected override void OnAppearing()
|
|
{
|
|
var url = this._url.RemoveQueryParams("host", "node", "id", "ptz").ToString();
|
|
var media = new Media(_libvlc, url, FromType.FromLocation);
|
|
if (Device.RuntimePlatform == Device.Android)
|
|
{
|
|
media.AddOption(new MediaConfiguration() { EnableHardwareDecoding = true });
|
|
media.AddOption(":network-caching=200");
|
|
//media.AddOption(":clock-jitter=0");
|
|
//media.AddOption(":clock-synchro=0");
|
|
}
|
|
var player = new MediaPlayer(_libvlc)
|
|
{
|
|
Volume = 0
|
|
};
|
|
videoView.MediaPlayer = player;
|
|
player.Play(media);
|
|
}
|
|
|
|
protected override void OnDisappearing()
|
|
{
|
|
if (this.videoView.MediaPlayer.IsPlaying)
|
|
{
|
|
this.videoView.MediaPlayer.Stop();
|
|
}
|
|
}
|
|
|
|
private void Back_Clicked(object sender, EventArgs e)
|
|
{
|
|
if (this.videoView.MediaPlayer.IsPlaying)
|
|
{
|
|
this.videoView.MediaPlayer.Stop();
|
|
}
|
|
this.Navigation.PopAsync();
|
|
}
|
|
|
|
private void Volume_ValueChanged(object sender, ValueChangedEventArgs e)
|
|
{
|
|
if (this.videoView?.MediaPlayer != null)
|
|
{
|
|
this.videoView.MediaPlayer.Volume = (int)e.NewValue;
|
|
if (this.videoView.MediaPlayer.Volume == 0 && this.mute.Source.ClassId != "mute.png")
|
|
{
|
|
this.mute.Source = SetImage("mute.png");
|
|
}
|
|
else if (this.mute.Source.ClassId != "volume.png")
|
|
{
|
|
this.mute.Source = SetImage("volume.png");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Mute_Clicked(object sender, EventArgs e)
|
|
{
|
|
if (this.videoView?.MediaPlayer != null)
|
|
{
|
|
if (this.videoView.MediaPlayer.Volume == 0)
|
|
{
|
|
this.volume.Value = 50;
|
|
}
|
|
else
|
|
{
|
|
this.volume.Value = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Control_Pressed(object sender, EventArgs e)
|
|
{
|
|
var videoUrl = new Url(this._url);
|
|
var url = videoUrl.QueryParams["host"].ToString() + "/App/Exec/";
|
|
url = url.SetQueryParam("node", videoUrl.QueryParams["node"]);
|
|
url = url.SetQueryParam("id", videoUrl.QueryParams["id"]);
|
|
var btn = sender as ImageButton;
|
|
url = url.SetQueryParam("cmd", btn.ClassId);
|
|
Console.WriteLine(url);
|
|
var client = new HttpClient();
|
|
client.GetAsync(url).Wait();
|
|
}
|
|
|
|
private void Control_Released(object sender, EventArgs e)
|
|
{
|
|
var videoUrl = new Url(this._url);
|
|
var url = videoUrl.QueryParams["host"].ToString() + "/App/Exec/";
|
|
url = url.SetQueryParam("node", videoUrl.QueryParams["node"]);
|
|
url = url.SetQueryParam("id", videoUrl.QueryParams["id"]);
|
|
url = url.SetQueryParam("cmd", "23stop");
|
|
Console.WriteLine(url);
|
|
var client = new HttpClient();
|
|
client.GetAsync(url).Wait();
|
|
}
|
|
|
|
private ImageSource SetImage(string image)
|
|
{
|
|
var result = ImageSource.FromResource($"Demo.wwwroot.images.{image}");
|
|
result.ClassId = image;
|
|
return result;
|
|
}
|
|
}
|
|
} |