75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
|
|
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Media;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using LibVLCSharp.Shared;
|
|
using Tesses.CMS.Avalonia.Models;
|
|
using Tesses.CMS.Avalonia.Views.HomePages;
|
|
using Tesses.CMS.Client;
|
|
namespace Tesses.CMS.Avalonia.ViewModels.HomePages;
|
|
|
|
public partial class HomeMovieVideoPlayerViewModel : ViewModelBase, IBackable, IDisposable
|
|
{
|
|
HomePageViewModel home;
|
|
|
|
HomeMoviePageViewModel moviePage;
|
|
|
|
LibVLC vlc=new LibVLC("--input-repeat=65535");
|
|
|
|
public HomeMovieVideoPlayerViewModel(HomePageViewModel home,HomeMoviePageViewModel moviePage, string url)
|
|
{
|
|
|
|
this.home = home;
|
|
this.moviePage = moviePage;
|
|
|
|
|
|
|
|
|
|
Player=new MediaPlayer(new Media(vlc,url,FromType.FromLocation));
|
|
|
|
Player.Play();
|
|
}
|
|
public HomeMovieVideoPlayerViewModel(HomePageViewModel home,HomeMoviePageViewModel moviePage, Stream strm)
|
|
{
|
|
this.Stream = strm;
|
|
this.home = home;
|
|
this.moviePage = moviePage;
|
|
|
|
|
|
LibVLC vlc=new LibVLC("--input-repeat=65535");
|
|
|
|
Player=new MediaPlayer(new Media(vlc,new StreamMediaInput(strm)));
|
|
|
|
Player.Play();
|
|
}
|
|
[ObservableProperty]
|
|
private MediaPlayer? _player;
|
|
|
|
|
|
public ViewModelBase Back()
|
|
{
|
|
|
|
return moviePage;
|
|
}
|
|
Stream? Stream=null;
|
|
|
|
public void Dispose()
|
|
{
|
|
|
|
Thread thrd=new Thread(()=>{
|
|
Player?.Stop();
|
|
Thread.Sleep(10000);
|
|
Player?.Dispose();
|
|
Stream?.Dispose();
|
|
vlc.Dispose();
|
|
});
|
|
thrd.Start();
|
|
}
|
|
} |