Commit 70678b32 authored by Martin Finkel's avatar Martin Finkel

Cleanup playback start

parent 7968641c
......@@ -10,8 +10,8 @@ namespace LocalNetwork.ViewModels
public ItemDetailViewModel(Item item)
{
_item = item;
MediaPlayer = new MediaPlayer(item.Media);
MediaPlayer.Play();
_mediaPlayer = new MediaPlayer(item.Media);
}
private MediaPlayer _mediaPlayer;
......@@ -20,5 +20,18 @@ namespace LocalNetwork.ViewModels
get => _mediaPlayer;
private set => SetProperty(ref _mediaPlayer, value);
}
public void Play()
{
MediaPlayer = _mediaPlayer;
MediaPlayer.Play();
}
public void Stop()
{
MediaPlayer.Stop();
MediaPlayer.Dispose();
_item.Media.Dispose();
}
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ namespace LocalNetwork.ViewModels
public ItemsViewModel()
{
Title = "Browse Local Network";
Title = "Local Network";
Items = new ObservableCollection<Item>();
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
......@@ -88,7 +88,7 @@ namespace LocalNetwork.ViewModels
Core.Initialize();
_libVLC = new LibVLC();
_libVLC = new LibVLC("--verbose=2");
}
private void DiscoverNetworkShares() => _mediaDiscoverers.ForEach(md => md.Start());
......
......@@ -3,5 +3,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LocalNetwork.Views.ItemDetailPage"
xmlns:vlc="clr-namespace:LibVLCSharp.Forms.Shared;assembly=LibVLCSharp.Forms">
<vlc:VideoView MediaPlayer="{Binding MediaPlayer}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<vlc:VideoView MediaPlayer="{Binding MediaPlayer}" MediaPlayerChanged="VideoView_MediaPlayerChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</ContentPage>
\ No newline at end of file
......@@ -16,5 +16,17 @@ namespace LocalNetwork.Views
BindingContext = this.viewModel = viewModel;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
viewModel.Stop();
}
private void VideoView_MediaPlayerChanged(object sender, LibVLCSharp.Shared.MediaPlayerChangedEventArgs e)
{
viewModel.Play();
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using LocalNetwork.Models;
using LocalNetwork.Views;
using LocalNetwork.ViewModels;
using LibVLCSharp.Forms.Shared;
using LibVLCSharp.Shared;
namespace LocalNetwork.Views
{
......
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