From 5eb56f2335a2a444c7c7dfad342103e6a7ff3c0a Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Tue, 30 Apr 2019 16:53:38 +0300 Subject: [PATCH] - Cursor hiding on playback removed - Ad free version price is displayed now - Video player muxed streams playback development --- FoxTube/Assets/Data/Patchnotes.xml | 4 +-- FoxTube/Classes/SecretsVault.cs | 2 +- FoxTube/Classes/VideoProcessor.cs | 38 +++++++++++++++++++-- FoxTube/Controls/Player/VideoPlayer.xaml | 3 +- FoxTube/Controls/Player/VideoPlayer.xaml.cs | 34 +++++------------- FoxTube/Pages/MainPage.xaml | 2 +- FoxTube/Pages/MainPage.xaml.cs | 1 + 7 files changed, 50 insertions(+), 34 deletions(-) diff --git a/FoxTube/Assets/Data/Patchnotes.xml b/FoxTube/Assets/Data/Patchnotes.xml index 49b14e6..b9ee5f3 100644 --- a/FoxTube/Assets/Data/Patchnotes.xml +++ b/FoxTube/Assets/Data/Patchnotes.xml @@ -8,7 +8,6 @@ - Fixed ads watermarks on video when it was opened through notification - Fixed videos loading - Fixed special characters appearing in toast notifications -- Cursor now hides on playback - History page re-design - Added app history management (doesn't affect web site's history) - Extended history information for videos (watching progress) @@ -17,6 +16,7 @@ - If video is longer than 1 hour ads will be shown every 30 minutes - Added incognito mode (available in video card context menu) - Search suggestions now run smoother +- FoxTube pro price is now displayed in menu ### Что нового: - Исправлена проблема получения истории, "Посмотреть позже" и рекомендаций @@ -24,7 +24,6 @@ - Исправлено появление водяных занков рекламы на видео при открытии через уведомления - Исправлена загрузка видео - Исправлено появление особых символов в уведомлениях -- Теперь курсор скрывается при просмотре - Редизайн страницы истории - Добавлено управление историей просмотра приложения (не влияет на историю просмотров на сайте) - Расширенная информация о просмотренном видео (прогресс просмотра) @@ -33,6 +32,7 @@ - Если видео длится более 1 часа, рекламный баннер будет появляться каждые 30 минут - Добавлен режим инкогнито (доступен в контекстном меню видео карточки) - Подсказки при поиске работают плавнее +- Теперь на кнопке отключения рекламы отображается текущая цена diff --git a/FoxTube/Classes/SecretsVault.cs b/FoxTube/Classes/SecretsVault.cs index ab7d4ea..8bd72a4 100644 --- a/FoxTube/Classes/SecretsVault.cs +++ b/FoxTube/Classes/SecretsVault.cs @@ -257,7 +257,7 @@ namespace FoxTube if (!requset.Products["9NP1QK556625"].IsInUserCollection) { AdsDisabled = false; - Purchased?.Invoke(args:false); + Purchased?.Invoke(null, false, requset.Products["9NP1QK556625"].Price.FormattedPrice); } } catch { } diff --git a/FoxTube/Classes/VideoProcessor.cs b/FoxTube/Classes/VideoProcessor.cs index 36dc814..c5a976e 100644 --- a/FoxTube/Classes/VideoProcessor.cs +++ b/FoxTube/Classes/VideoProcessor.cs @@ -1,35 +1,69 @@ using System; using System.Collections.Generic; using System.Linq; +using System.IO; using System.Text; using System.Threading.Tasks; using YoutubeExplode.Models.MediaStreams; using Windows.Media.Editing; using Windows.Media.Core; using Windows.Storage; +using Windows.UI.Xaml.Controls; +using System.Net; +using YoutubeExplode; namespace FoxTube.Classes { public class VideoProcessor { - public VideoPlayer Player { get; set; } + public MediaElement Player { get; set; } MediaComposition composition = new MediaComposition(); StorageFolder roaming = ApplicationData.Current.RoamingFolder; StorageFile audioCache; StorageFile videoCache; - public async Task GetStream(MediaStreamInfo video, MediaStreamInfo audio) + MediaStream videoStream; + MediaStream audioStream; + + YoutubeClient client = new YoutubeClient(SecretsVault.HttpClient); + + public VideoProcessor() + { + //Player.CurrentStateChanged += Player_CurrentStateChanged; + } + + public async Task GetStream(VideoStreamInfo video, AudioStreamInfo audio) { audioCache = await roaming.CreateFileAsync("audioCache.mp4", CreationCollisionOption.ReplaceExisting); videoCache = await roaming.CreateFileAsync("videoCache.mp4", CreationCollisionOption.ReplaceExisting); + videoStream = await client.GetMediaStreamAsync(video); + audioStream = await client.GetMediaStreamAsync(audio); + /*Stream write = await videoCache.OpenStreamForWriteAsync(); + write. + write.WriteAsync()*/ + + videoStream.BeginRead(new byte[300 * video.Bitrate], (int)((int)Player.Position.TotalSeconds * video.Bitrate), (int)((int)Player.Position.Add(TimeSpan.FromMinutes(5)).TotalSeconds * video.Bitrate - (int)Player.Position.TotalSeconds * video.Bitrate), null, null); composition.BackgroundAudioTracks.Add(await BackgroundAudioTrack.CreateFromFileAsync(audioCache)); composition.Clips.Add(await MediaClip.CreateFromFileAsync(videoCache)); return composition.GenerateMediaStreamSource(); } + + public async void Close() + { + await audioCache.DeleteAsync(StorageDeleteOption.PermanentDelete); + await videoCache.DeleteAsync(StorageDeleteOption.PermanentDelete); + } + + private void Player_CurrentStateChanged(object sender, Windows.UI.Xaml.RoutedEventArgs e) + { + throw new NotImplementedException(); + } + + } } diff --git a/FoxTube/Controls/Player/VideoPlayer.xaml b/FoxTube/Controls/Player/VideoPlayer.xaml index 70b1de7..fd0fc73 100644 --- a/FoxTube/Controls/Player/VideoPlayer.xaml +++ b/FoxTube/Controls/Player/VideoPlayer.xaml @@ -8,8 +8,7 @@ mc:Ignorable="d" d:DesignHeight="1080" d:DesignWidth="1920" - RequestedTheme="Dark" - PointerMoved="UserControl_PointerMoved"> + RequestedTheme="Dark"> diff --git a/FoxTube/Controls/Player/VideoPlayer.xaml.cs b/FoxTube/Controls/Player/VideoPlayer.xaml.cs index 47bb6b0..7a823a9 100644 --- a/FoxTube/Controls/Player/VideoPlayer.xaml.cs +++ b/FoxTube/Controls/Player/VideoPlayer.xaml.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Windows.UI.Core; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -9,9 +8,9 @@ using Windows.Media; using Windows.Storage.Streams; using YoutubeExplode.Models.MediaStreams; using YoutubeExplode; -using System.Diagnostics; -using Windows.Foundation; +using System.IO; using FoxTube.Classes; +using Windows.Media.Core; namespace FoxTube { @@ -31,9 +30,7 @@ namespace FoxTube set { videoSource.Position = value; } } - VideoProcessor processor = new VideoProcessor(); - - DispatcherTimer cursorTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5) }; + VideoProcessor processor; TimeSpan timecodeBackup; bool needUpdateTimecode = false; @@ -95,20 +92,11 @@ namespace FoxTube public void InitializeContols() { - videoSource.Volume = SettingsStorage.Volume; - - cursorTimer.Tick += (s, e) => + processor = new VideoProcessor { - Point cursorPoint = CoreWindow.GetForCurrentThread().PointerPosition; - cursorPoint.X -= Window.Current.Bounds.X; - cursorPoint.Y -= Window.Current.Bounds.Y; - Rect playerBounds = TransformToVisual(Methods.MainPage).TransformBounds(new Rect(0, 0, ActualWidth, ActualHeight)); - - if((cursorPoint.Y > playerBounds.Top && cursorPoint.Y < playerBounds.Bottom && - cursorPoint.X > playerBounds.Left && cursorPoint.X < playerBounds.Right) || videoSource.IsFullWindow) - CoreWindow.GetForCurrentThread().PointerCursor = null; - cursorTimer.Stop(); + Player = videoSource }; + videoSource.Volume = SettingsStorage.Volume; Controls.CloseRequested += Controls_CloseRequested; Controls.NextRequested += (s, e) => NextClicked?.Invoke(); @@ -155,7 +143,8 @@ namespace FoxTube if (requestedQuality is MuxedStreamInfo) videoSource.Source = requestedQuality.Url.ToUri(); else - videoSource.SetMediaStreamSource(await processor.GetStream(requestedQuality, list.Audio.First())); + videoSource.SetPlaybackSource(MediaSource.CreateFromStream((await new YoutubeClient().GetMediaStreamAsync(requestedQuality)).AsRandomAccessStream(), "video")); + //videoSource.SetMediaStreamSource(await processor.GetStream(requestedQuality as VideoStreamInfo, list.Audio.First())); } public void Controls_CloseRequested(object sender, RoutedEventArgs e) @@ -235,12 +224,5 @@ namespace FoxTube { Controls.Advert.PushAdvert(); } - - private void UserControl_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) - { - if (CoreWindow.GetForCurrentThread().PointerCursor == null) - CoreWindow.GetForCurrentThread().PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0); - cursorTimer.Start(); - } } } diff --git a/FoxTube/Pages/MainPage.xaml b/FoxTube/Pages/MainPage.xaml index c01bd43..2c69d66 100644 --- a/FoxTube/Pages/MainPage.xaml +++ b/FoxTube/Pages/MainPage.xaml @@ -126,7 +126,7 @@ --> - + diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index f99d36e..1fa2b8d 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -45,6 +45,7 @@ namespace FoxTube SecretsVault.Purchased += async (sender, e) => { removeAds.Visibility = (e[0] as bool?).Value ? Visibility.Collapsed : Visibility.Visible; + removeAds.Content = $"{resources.GetString("/Main/adsFree/Content")} ({e[1]})"; if (!(bool)e[0]) return;