Commit 60c354a2 authored by Martin Finkel's avatar Martin Finkel

initial chromecast UI setup

parent b032f7da

using Autofac;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using VLC.Controls;
using VLC.Helpers;
......@@ -19,13 +17,11 @@ using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Foundation.Metadata;
using Windows.Gaming.Input;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
......@@ -43,7 +39,7 @@ namespace VLC
public static OpenFilePickerReason OpenFilePickerReason = OpenFilePickerReason.Null;
public static Model.Music.AlbumItem SelectedAlbumItem;
public static IContainer Container;
public App()
{
InitializeComponent();
......@@ -319,11 +315,12 @@ namespace VLC
ToggleMediaCenterMode();
Locator.ExternalDeviceService.StartWatcher();
Locator.RendererService.Start();
if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Xbox)
await Locator.HttpServer.Bind(8080).ConfigureAwait(false);
}
public static void ReloadApplicationPage()
{
Locator.PlaybackService.Stop();
......
......@@ -155,6 +155,7 @@ namespace VLC.Services.RunTime
private PlayingType _playingType;
public PlayingType PlayingType
{
get { return _playingType; }
......@@ -210,6 +211,7 @@ namespace VLC.Services.RunTime
Task.Run(() => _playlistService.Restore());
}
#endif
private async void onCurrentMediaChanged(IMediaItem media, bool isRewind)
{
await SetMedia(media);
......@@ -362,24 +364,10 @@ namespace VLC.Services.RunTime
CurrentMedia.addOption($":start-time={pos}");
}
if (_mediaPlayer == null)
{
_mediaPlayer = new MediaPlayer(CurrentMedia);
var em = _mediaPlayer.eventManager();
em.OnBuffering += Playback_MediaBuffering;
em.OnStopped += OnStopped;
em.OnPlaying += OnPlaying;
em.OnPaused += OnPaused;
em.OnTimeChanged += Playback_MediaTimeChanged;
em.OnEndReached += OnEndReached;
em.OnEncounteredError += Playback_MediaFailed;
em.OnLengthChanged += Playback_MediaLengthChanged;
em.OnTrackAdded += OnTrackAdded;
em.OnTrackDeleted += OnTrackDeleted;
em.OnPlaying += Playback_MediaPlaying;
em.OnPaused += Playback_MediaPaused;
em.OnOpening += Playback_Opening;
InitializeMediaPlayer();
}
else
_mediaPlayer.setMedia(CurrentMedia);
......@@ -387,6 +375,27 @@ namespace VLC.Services.RunTime
SetEqualizer(Locator.SettingsVM.Equalizer);
}
void InitializeMediaPlayer()
{
_mediaPlayer = CurrentMedia != null ? new MediaPlayer(CurrentMedia) : new MediaPlayer(Instance);
var em = _mediaPlayer.eventManager();
em.OnBuffering += Playback_MediaBuffering;
em.OnStopped += OnStopped;
em.OnPlaying += OnPlaying;
em.OnPaused += OnPaused;
em.OnTimeChanged += Playback_MediaTimeChanged;
em.OnEndReached += OnEndReached;
em.OnEncounteredError += Playback_MediaFailed;
em.OnLengthChanged += Playback_MediaLengthChanged;
em.OnTrackAdded += OnTrackAdded;
em.OnTrackDeleted += OnTrackDeleted;
em.OnPlaying += Playback_MediaPlaying;
em.OnPaused += Playback_MediaPaused;
em.OnOpening += Playback_Opening;
}
/// <summary>
/// Only this method should set the CurrentMedia property of TrackCollection.
/// </summary>
......@@ -670,6 +679,16 @@ namespace VLC.Services.RunTime
_mediaPlayer.updateViewpoint(viewpoint, absolute);
}
public void SetRenderer(string rendererItemName)
{
var rendererItem = Locator.RendererService.RendererItems.FirstOrDefault(ri => ri.name().Equals(rendererItemName));
if (rendererItem == null) return;
if(_mediaPlayer == null)
InitializeMediaPlayer();
_mediaPlayer.setRenderer(rendererItem);
}
#endregion
#region Playback events callbacks
......
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using libVLCX;
using VLC.Commands;
using VLC.Helpers;
using VLC.Utils;
using VLC.ViewModels;
namespace VLC.Services.RunTime
{
public class RendererService
{
public ObservableCollection<RendererItem> RendererItems { get; } = new ObservableCollection<RendererItem>();
RendererDiscoverer _rendererDiscoverer;
public bool IsStarted;
public void Start()
{
if (IsStarted) return;
IsStarted = true;
Task.Run(async () =>
{
await Locator.PlaybackService.Initialize();
if(_rendererDiscoverer == null)
{
_rendererDiscoverer = new RendererDiscoverer(Locator.PlaybackService.Instance,
Locator.PlaybackService.Instance.rendererDiscoverers().First().name());
}
_rendererDiscoverer.eventManager().OnItemAdded += OnOnItemAdded;
_rendererDiscoverer.eventManager().OnRendererItemDeleted += OnOnRendererItemDeleted;
Debug.Assert(_rendererDiscoverer.start());
});
}
public void StopRendererDiscoverer()
{
if (!IsStarted) return;
IsStarted = false;
_rendererDiscoverer.stop();
_rendererDiscoverer.eventManager().OnItemAdded -= OnOnItemAdded;
_rendererDiscoverer.eventManager().OnRendererItemDeleted -= OnOnRendererItemDeleted;
_rendererDiscoverer = null;
RendererItems.Clear();
}
void OnOnRendererItemDeleted(RendererItem rendererItem)
{
RendererItems.Remove(rendererItem);
}
void OnOnItemAdded(RendererItem rendererItem)
{
RendererItems.Add(rendererItem);
Debug.WriteLine("Found new rendererItem " + rendererItem.name() + " can render audio " + rendererItem.canRenderAudio() + " can render video " + rendererItem.canRenderVideo());
}
public Visibility HasRenderer => DeviceHelper.GetDeviceType() != DeviceTypeEnum.Xbox && RendererItems.Any()
? Visibility.Visible : Visibility.Collapsed;
public MenuFlyout CreateRendererFlyout()
{
var flyout = new MenuFlyout();
foreach (var ri in RendererItems)
{
flyout.Items.Add(new MenuFlyoutItem
{
Text = ri.name(),
Command = new ActionCommand(() => Locator.PlaybackService.SetRenderer(ri.name()))
});
}
return flyout;
}
}
}
\ No newline at end of file
......@@ -68,6 +68,7 @@ namespace VLC.Utils
builder.RegisterType<HttpServer>().SingleInstance();
builder.RegisterType<FileCopyService>().SingleInstance();
builder.RegisterType<PlaylistService>().SingleInstance();
builder.RegisterType<RendererService>().SingleInstance();
return builder.Build();
}
......
......@@ -201,6 +201,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\NavigationService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\PlaybackService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\PlaylistService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\RendererService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\VideoMetaService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\MouseService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\RunTime\MusicMetaService.cs" />
......
......@@ -55,6 +55,7 @@ namespace VLC.ViewModels
private static MetroSlideshow _metroSlideshow;
private static HttpServer _httpServer;
private static FileCopyService _fileCopyService;
static RendererService _rendererService;
public Locator()
{
......@@ -99,5 +100,6 @@ namespace VLC.ViewModels
public static MetroSlideshow Slideshow => _metroSlideshow ?? (_metroSlideshow = App.Container.Resolve<MetroSlideshow>());
public static HttpServer HttpServer => _httpServer ?? (_httpServer = App.Container.Resolve<HttpServer>());
public static FileCopyService FileCopyService => _fileCopyService ?? (_fileCopyService = App.Container.Resolve<FileCopyService>());
public static RendererService RendererService => _rendererService ?? (_rendererService = App.Container.Resolve<RendererService>());
}
}
\ No newline at end of file
......@@ -113,5 +113,16 @@
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>
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Xaml.Interactivity;
using VLC.Helpers;
using VLC.ViewModels;
using Windows.UI.Xaml.Input;
......@@ -18,6 +16,8 @@ namespace VLC.UI.Views.MainPages.MusicPanes
public SongCollectionBase()
{
this.InitializeComponent();
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
}
private void SemanticZoom_OnViewChangeCompleted(object sender, SemanticZoomViewChangedEventArgs e)
......
......@@ -147,6 +147,7 @@
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<AppBarToggleButton Grid.Column="1"
......@@ -184,9 +185,19 @@
FontSize="20"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Grid.Column="4"
x:Name="Cast"
Style="{StaticResource AppBarButtonStyleHuge}"
IsCompact="True"
Visibility="{Binding Source={StaticResource Locator}, Path=RendererService.HasRenderer}">
<AppBarButton.Content>
<FontIcon Glyph="&#xEC15;"
FontSize="20"
FontFamily="Segoe MDL2 Assets" />
</AppBarButton.Content>
</AppBarButton>
</Grid>
<Grid Grid.Row="10"
HorizontalAlignment="Center"
MaxWidth="400">
......
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using Windows.Devices.Input;
using Windows.UI;
......@@ -24,6 +25,7 @@ namespace VLC.UI.Views.MusicPages
this.Loaded += MusicPlayerPage_Loaded;
_white = new SolidColorBrush(Colors.White);
_red = new SolidColorBrush(Colors.Red);
Cast.Flyout = Locator.RendererService.CreateRendererFlyout();
}
void MusicPlayerPage_Loaded(object sender, RoutedEventArgs e)
......@@ -35,6 +37,12 @@ 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();
}
void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
......@@ -88,6 +96,7 @@ namespace VLC.UI.Views.MusicPages
_viewModel.PropertyChanged -= MediaPlaybackViewModelOnPropertyChanged;
if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Tablet)
PointerWheelChanged -= OnPointerWheelChanged;
Locator.RendererService.RendererItems.CollectionChanged -= RendererItemsOnCollectionChanged;
}
void Responsive()
......
......@@ -256,6 +256,20 @@
FontSize="22" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton x:Name="CastButton"
IsCompact="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{StaticResource AppBarButtonStyleHuge}"
Margin="{StaticResource FrameMarginHorizontal}"
Visibility="{Binding Source={StaticResource Locator}, Path=RendererService.HasRenderer}">
<AppBarButton.Content>
<FontIcon Glyph="&#xEC15;"
FontFamily="Segoe MDL2 Assets" />
</AppBarButton.Content>
</AppBarButton>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<AppBarButton x:Name="PreviousButton"
......
......@@ -8,6 +8,7 @@
**********************************************************************/
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
......@@ -120,6 +121,8 @@ 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();
// VM initialization
Locator.VideoPlayerVm.OnNavigatedTo();
......@@ -137,7 +140,12 @@ namespace VLC.UI.Views.VideoPages
// Swapchain animations
App.RootPage.StartCompositionAnimationOnSwapChain(false);
}
void RendererItemsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
{
CastButton.Flyout = Locator.RendererService.CreateRendererFlyout();
}
void MediaPlaybackViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Locator.MediaPlaybackViewModel.Volume))
......@@ -184,6 +192,7 @@ namespace VLC.UI.Views.VideoPages
AppViewHelper.LeaveFullscreen();
Locator.MediaPlaybackViewModel.PropertyChanged -= MediaPlaybackViewModelOnPropertyChanged;
Locator.RendererService.RendererItems.CollectionChanged -= RendererItemsOnCollectionChanged;
_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