diff --git a/FoxTube/Controls/Adverts/PlayerAdvert.xaml b/FoxTube/Controls/Adverts/PlayerAdvert.xaml
new file mode 100644
index 0000000..9eab1e2
--- /dev/null
+++ b/FoxTube/Controls/Adverts/PlayerAdvert.xaml
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+ Collapsed
+
+
+
+
+ Visible
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Visible
+
+
+
+
+ Collapsed
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FoxTube/Controls/Adverts/PlayerAdvert.xaml.cs b/FoxTube/Controls/Adverts/PlayerAdvert.xaml.cs
new file mode 100644
index 0000000..78d18dc
--- /dev/null
+++ b/FoxTube/Controls/Adverts/PlayerAdvert.xaml.cs
@@ -0,0 +1,82 @@
+using Microsoft.Advertising.WinRT.UI;
+using System;
+using System.Collections.Generic;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+
+namespace FoxTube.Controls.Adverts
+{
+ public sealed partial class PlayerAdvert : UserControl
+ {
+ NativeAdsManagerV2 manager = new NativeAdsManagerV2(SecretsVault.AppId, SecretsVault.AdUnitId);
+ NativeAdV2 advert;
+
+ DispatcherTimer timer = new DispatcherTimer()
+ {
+ Interval = TimeSpan.FromMilliseconds(10000)
+ };
+ public PlayerAdvert()
+ {
+ InitializeComponent();
+
+ manager.AdReady += AdReady;
+ manager.ErrorOccurred += ErrorOccurred;
+
+ timer.Tick += (s, e) =>
+ {
+ timer.Stop();
+ hide.Begin();
+ };
+ }
+
+ private void ErrorOccurred(object sender, NativeAdErrorEventArgs e)
+ {
+ System.Diagnostics.Debug.WriteLine("Error has occured while loading ad");
+ }
+
+ private void AdReady(object sender, NativeAdReadyEventArgs arg)
+ {
+ advert = arg.NativeAd;
+
+ title.Text = advert.Title;
+ description.Text = Methods.GuardFromNull(advert.Description);
+
+ if (advert.AdIcon != null)
+ {
+ grid.Children.Insert(0, advert.AdIcon);
+
+ advert.AdIcon.HorizontalAlignment = HorizontalAlignment.Left;
+ advert.AdIcon.Margin = new Thickness(4);
+ advert.AdIcon.Width = double.NaN;
+ advert.AdIcon.Height = double.NaN;
+
+ advert.AdIcon.SizeChanged += (s, e) => grid.ColumnDefinitions[0].Width = new GridLength(advert.AdIcon.ActualWidth + 8);
+ }
+
+ cta.Content = Methods.GuardFromNull(advert.CallToActionText);
+ cta.Visibility = string.IsNullOrWhiteSpace(advert.CallToActionText) ? Visibility.Collapsed : Visibility.Visible;
+
+ info.Text += advert.Price;
+ info.Text += " " + advert.Rating;
+
+ if (cta.Visibility == Visibility.Collapsed)
+ advert.RegisterAdContainer(grid);
+ else
+ advert.RegisterAdContainer(grid, new List { cta });
+
+ timer.Start();
+ show.Begin();
+ }
+
+ public void PushAdvert()
+ {
+ manager.RequestAd();
+ }
+
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ timer.Stop();
+ hide.Begin();
+ }
+ }
+}
diff --git a/FoxTube/Controls/Player/PlayerControls.cs b/FoxTube/Controls/Player/PlayerControls.cs
index dabf9c6..5347506 100644
--- a/FoxTube/Controls/Player/PlayerControls.cs
+++ b/FoxTube/Controls/Player/PlayerControls.cs
@@ -1,4 +1,5 @@
using FoxTube.Controls;
+using FoxTube.Controls.Adverts;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -28,6 +29,7 @@ namespace FoxTube
public event QualityChangedEventHandler QualityChanged;
public MediaElement Player;
+ public PlayerAdvert Advert;
public IReadOnlyList ClosedCaptions { get; set; }
public MediaStreamInfoSet MediaStreams { get; set; }
@@ -44,6 +46,8 @@ namespace FoxTube
{
isReady = true;
+ Advert = GetTemplateChild("ad") as PlayerAdvert;
+
(GetTemplateChild("close") as Button).Click += Close_Click;
(GetTemplateChild("compactClose") as Button).Click += Close_Click;
@@ -200,6 +204,8 @@ namespace FoxTube
(GetTemplateChild("dragholder") as Button).Visibility = Visibility.Visible;
(GetTemplateChild("captions") as LiveCaptions).Size = 15;
+
+ (GetTemplateChild("root") as Grid).RowDefinitions[1].Height = new GridLength(0);
}
public void SetMinimized()
@@ -225,6 +231,8 @@ namespace FoxTube
(GetTemplateChild("maximize") as Button).Visibility = Visibility.Visible;
(GetTemplateChild("captions") as LiveCaptions).Size = 15;
+
+ (GetTemplateChild("root") as Grid).RowDefinitions[1].Height = new GridLength(0);
}
public void SetNormal()
@@ -249,6 +257,8 @@ namespace FoxTube
(GetTemplateChild("captions") as LiveCaptions).Size = 24;
(GetTemplateChild("dragholder") as Button).Visibility = Visibility.Collapsed;
+
+ (GetTemplateChild("root") as Grid).RowDefinitions[1].Height = new GridLength(1, GridUnitType.Auto);
}
public void SetMeta(string title, string channel)
diff --git a/FoxTube/Controls/Player/VideoPlayer.xaml b/FoxTube/Controls/Player/VideoPlayer.xaml
index 7efbed1..3d67ab2 100644
--- a/FoxTube/Controls/Player/VideoPlayer.xaml
+++ b/FoxTube/Controls/Player/VideoPlayer.xaml
@@ -11,7 +11,7 @@
RequestedTheme="Dark">
-
+
5)
+ videoSource.Markers.Add(new Windows.UI.Xaml.Media.TimelineMarker { Time = Methods.GetDuration(item.ContentDetails.Duration) - TimeSpan.FromMinutes(1) });
Controls.SetQualities(await new YoutubeClient().GetVideoMediaStreamInfosAsync(item.Id));
Controls.SetCaptions(await new YoutubeClient().GetVideoClosedCaptionTrackInfosAsync(item.Id));
}
@@ -230,5 +232,10 @@ namespace FoxTube
audioSource.Volume = videoSource.Volume;
SettingsStorage.Volume = videoSource.Volume;
}
+
+ private void VideoSource_MarkerReached(object sender, Windows.UI.Xaml.Media.TimelineMarkerRoutedEventArgs e)
+ {
+ Controls.Advert.PushAdvert();
+ }
}
}
diff --git a/FoxTube/FoxTube.csproj b/FoxTube/FoxTube.csproj
index 85b9eff..77bacd7 100644
--- a/FoxTube/FoxTube.csproj
+++ b/FoxTube/FoxTube.csproj
@@ -116,6 +116,9 @@
CommentAdvert.xaml
+
+ PlayerAdvert.xaml
+
ChannelCard.xaml
@@ -289,6 +292,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/FoxTube/Pages/VideoPage.xaml b/FoxTube/Pages/VideoPage.xaml
index 1eff296..4fd9279 100644
--- a/FoxTube/Pages/VideoPage.xaml
+++ b/FoxTube/Pages/VideoPage.xaml
@@ -6,7 +6,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="using:FoxTube.Pages"
- xmlns:controls="using:FoxTube.Controls"
mc:Ignorable="d">
diff --git a/FoxTube/Themes/Generic.xaml b/FoxTube/Themes/Generic.xaml
index 7e2613e..3f0397a 100644
--- a/FoxTube/Themes/Generic.xaml
+++ b/FoxTube/Themes/Generic.xaml
@@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube"
- xmlns:controls="using:FoxTube.Controls">
+ xmlns:controls="using:FoxTube.Controls"
+ xmlns:adverts="using:FoxTube.Controls.Adverts">
-
+
@@ -628,6 +634,8 @@
+
+