Commit 3818025a authored by Martin Finkel's avatar Martin Finkel

Add disconnect cc option + cleanup views

parent 5901029d
......@@ -153,6 +153,7 @@ namespace VLC
{
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
Locator.PlaybackService?.Trim();
Locator.RendererService.Stop();
deferral.Complete();
}
......
......@@ -655,12 +655,17 @@ namespace VLC.Services.RunTime
{
var rendererItem = Locator.RendererService.RendererItems.FirstOrDefault(ri => ri.name().Equals(rendererItemName));
if (rendererItem == null) return;
if(_mediaPlayer == null)
if (_mediaPlayer == null)
InitializeMediaPlayer();
_mediaPlayer.setRenderer(rendererItem);
}
public void DisconnectRenderer()
{
_mediaPlayer?.unsetRenderer();
}
#endregion
#region Playback events callbacks
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using libVLCX;
......@@ -11,14 +13,26 @@ using VLC.Commands;
using VLC.Helpers;
using VLC.Utils;
using VLC.ViewModels;
using WinRTXamlToolkit.Tools;
namespace VLC.Services.RunTime
{
public class RendererService
public class RendererService : BindableBase
{
public ObservableCollection<RendererItem> RendererItems { get; } = new ObservableCollection<RendererItem>();
RendererDiscoverer _rendererDiscoverer;
public bool IsStarted;
public bool IsRendererSet { get; set; }
readonly MenuFlyoutItem _disconnect = new MenuFlyoutItem
{
Text = Strings.Disconnect,
Command = new ActionCommand(() =>
{
Locator.PlaybackService.DisconnectRenderer();
Locator.RendererService.IsRendererSet = false;
})
};
public void Start()
{
......@@ -38,11 +52,11 @@ namespace VLC.Services.RunTime
_rendererDiscoverer.eventManager().OnItemAdded += OnOnItemAdded;
_rendererDiscoverer.eventManager().OnRendererItemDeleted += OnOnRendererItemDeleted;
Debug.Assert(_rendererDiscoverer.start());
_rendererDiscoverer.start();
});
}
public void StopRendererDiscoverer()
public void Stop()
{
if (!IsStarted) return;
......@@ -56,15 +70,23 @@ namespace VLC.Services.RunTime
RendererItems.Clear();
}
void OnOnRendererItemDeleted(RendererItem rendererItem)
async void OnOnRendererItemDeleted(RendererItem rendererItem)
{
RendererItems.Remove(rendererItem);
var match = RendererItems.FirstOrDefault(item => item.name().Equals(rendererItem.name()));
if (match != null)
RendererItems.Remove(match);
await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => OnPropertyChanged(nameof(HasRenderer)));
}
void OnOnItemAdded(RendererItem rendererItem)
async void OnOnItemAdded(RendererItem rendererItem)
{
LogHelper.Log("Found new rendererItem " + rendererItem.name() +
" can render audio " + rendererItem.canRenderAudio() +
" can render video " + rendererItem.canRenderVideo());
RendererItems.Add(rendererItem);
Debug.WriteLine("Found new rendererItem " + rendererItem.name() + " can render audio " + rendererItem.canRenderAudio() + " can render video " + rendererItem.canRenderVideo());
await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => OnPropertyChanged(nameof(HasRenderer)));
}
public Visibility HasRenderer => DeviceHelper.GetDeviceType() != DeviceTypeEnum.Xbox && RendererItems.Any()
......@@ -78,11 +100,14 @@ namespace VLC.Services.RunTime
flyout.Items.Add(new MenuFlyoutItem
{
Text = ri.name(),
Command = new ActionCommand(() => Locator.PlaybackService.SetRenderer(ri.name()))
Command = new ActionCommand(() =>
{
Locator.PlaybackService.SetRenderer(ri.name());
Locator.RendererService.IsRendererSet = true;
})
});
}
flyout.Items.Add(_disconnect);
return flyout;
}
}
......
......@@ -242,6 +242,7 @@ namespace VLC.Utils
public static string RemoveMusicFolderDescription => _resourcesLoader.GetString(nameof(RemoveMusicFolderDescription));
public static string AddFolder => _resourcesLoader.GetString(nameof(AddFolder));
public static string Connect => _resourcesLoader.GetString(nameof(Connect));
public static string Disconnect => _resourcesLoader.GetString(nameof(Disconnect));
public static string Reset => _resourcesLoader.GetString(nameof(Reset));
public static string ResetMusicDatabase => _resourcesLoader.GetString(nameof(ResetMusicDatabase));
public static string RefreshMusicLibrary => _resourcesLoader.GetString(nameof(RefreshMusicLibrary));
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -1165,6 +1165,10 @@
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
<trans-unit id="Disconnect" translate="yes" xml:space="preserve">
<source>disconnect</source>
<target state="new">disconnect</target>
</trans-unit>
</group>
</body>
</file>
......
......@@ -825,4 +825,7 @@
<data name="Restart" xml:space="preserve">
<value>restart</value>
</data>
<data name="Disconnect" xml:space="preserve">
<value>disconnect</value>
</data>
</root>
\ No newline at end of file
......@@ -98,6 +98,14 @@
<musicPanesControls:AlbumsCollectionButtons Grid.Column="2"
Visibility="{Binding AlbumsCollectionsButtonVisible}" />
<AppBarButton Grid.Column="3"
x:Name="Cast"
Visibility="{Binding Source={StaticResource Locator}, Path=RendererService.HasRenderer}">
<AppBarButton.Content>
<FontIcon Glyph="&#xEC15;"
FontFamily="Segoe MDL2 Assets" />
</AppBarButton.Content>
</AppBarButton>
<AppBarButton
Grid.Column="3"
Visibility="{Binding PlayArtistButtonVisible}"
......
......@@ -7,6 +7,7 @@
* Refer to COPYING file of the official project for license
**********************************************************************/
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
......@@ -34,6 +35,7 @@ namespace VLC.UI.Views.MainPages
Locator.MusicLibraryVM.PropertyChanged -= MusicLibraryVM_PropertyChanged;
await Locator.MusicLibraryVM.OnNavigatedFrom();
Cast.Click -= CastOnClick;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
......@@ -41,6 +43,12 @@ namespace VLC.UI.Views.MainPages
base.OnNavigatedTo(e);
Locator.MusicLibraryVM.PropertyChanged += MusicLibraryVM_PropertyChanged;
Cast.Click += CastOnClick;
}
void CastOnClick(object sender, RoutedEventArgs routedEventArgs)
{
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
}
private async void MusicPanesFrame_OnLoaded(object sender, RoutedEventArgs e)
......
......@@ -90,6 +90,14 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<AppBarButton Grid.Column="2"
x:Name="Cast"
Visibility="{Binding Source={StaticResource Locator}, Path=RendererService.HasRenderer}">
<AppBarButton.Content>
<FontIcon Glyph="&#xEC15;"
FontFamily="Segoe MDL2 Assets" />
</AppBarButton.Content>
</AppBarButton>
</Grid>
<ProgressRing Grid.Row="1"
IsActive="True"
......
......@@ -39,6 +39,7 @@ namespace VLC.UI.Views.MainPages
}
Locator.VideoLibraryVM.PropertyChanged += VideoLibraryVM_PropertyChanged;
Cast.Click += CastOnClick;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
......@@ -47,6 +48,12 @@ namespace VLC.UI.Views.MainPages
Locator.VideoLibraryVM.OnNavigatedFrom();
Locator.VideoLibraryVM.PropertyChanged -= VideoLibraryVM_PropertyChanged;
Cast.Click -= CastOnClick;
}
void CastOnClick(object sender, RoutedEventArgs routedEventArgs)
{
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
}
private void VideoLibraryVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
......
......@@ -113,16 +113,6 @@
FontFamily="{StaticResource VLCFont}" />
</AppBarButton.Content>
</AppBarButton>
<AppBarButton x:Name="Cast"
Style="{StaticResource CircleButtonStyle}"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Visibility="{Binding Source={StaticResource Locator}, Path=RendererService.HasRenderer}"
Margin="{StaticResource FrameMarginHorizontalPlusFooter}">
<AppBarButton.Content>
<FontIcon Glyph="&#xEC15;"
FontFamily="Segoe MDL2 Assets" />
</AppBarButton.Content>
</AppBarButton>
</Grid>
</Page>
......@@ -16,8 +16,6 @@ namespace VLC.UI.Views.MainPages.MusicPanes
public SongCollectionBase()
{
this.InitializeComponent();
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
}
private void SemanticZoom_OnViewChangeCompleted(object sender, SemanticZoomViewChangedEventArgs e)
......
......@@ -25,6 +25,10 @@ namespace VLC.UI.Views.MusicPages
this.Loaded += MusicPlayerPage_Loaded;
_white = new SolidColorBrush(Colors.White);
_red = new SolidColorBrush(Colors.Red);
}
void CastOnClick(object sender, RoutedEventArgs routedEventArgs)
{
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
}
......@@ -37,12 +41,7 @@ namespace VLC.UI.Views.MusicPages
_viewModel.PropertyChanged += MediaPlaybackViewModelOnPropertyChanged;
if(DeviceHelper.GetDeviceType() == DeviceTypeEnum.Tablet)
PointerWheelChanged += OnPointerWheelChanged;
Locator.RendererService.RendererItems.CollectionChanged += RendererItemsOnCollectionChanged;
}
void RendererItemsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
{
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
Cast.Click += CastOnClick;
}
void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
......@@ -96,7 +95,7 @@ namespace VLC.UI.Views.MusicPages
_viewModel.PropertyChanged -= MediaPlaybackViewModelOnPropertyChanged;
if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Tablet)
PointerWheelChanged -= OnPointerWheelChanged;
Locator.RendererService.RendererItems.CollectionChanged -= RendererItemsOnCollectionChanged;
Cast.Click -= CastOnClick;
}
void Responsive()
......
......@@ -121,8 +121,7 @@ namespace VLC.UI.Views.VideoPages
Locator.MediaPlaybackViewModel.PropertyChanged += MediaPlaybackViewModelOnPropertyChanged;
if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Tablet)
PointerWheelChanged += MouseWheelChanged;
Locator.RendererService.RendererItems.CollectionChanged += RendererItemsOnCollectionChanged;
CastButton.Flyout = Locator.RendererService.CreateRendererFlyout();
CastButton.Click += CastButtonOnClick;
// VM initialization
Locator.VideoPlayerVm.OnNavigatedTo();
......@@ -141,7 +140,7 @@ namespace VLC.UI.Views.VideoPages
App.RootPage.StartCompositionAnimationOnSwapChain(false);
}
void RendererItemsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
void CastButtonOnClick(object sender, RoutedEventArgs routedEventArgs)
{
CastButton.Flyout = Locator.RendererService.CreateRendererFlyout();
}
......@@ -192,7 +191,7 @@ namespace VLC.UI.Views.VideoPages
AppViewHelper.LeaveFullscreen();
Locator.MediaPlaybackViewModel.PropertyChanged -= MediaPlaybackViewModelOnPropertyChanged;
Locator.RendererService.RendererItems.CollectionChanged -= RendererItemsOnCollectionChanged;
CastButton.Click -= CastButtonOnClick;
_viewModel.MouseService.Stop();
_viewModel.MouseService.OnMoved -= ShowControlPanel;
......
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