diff --git a/Hohoema.Core/Models/Player/IStreamingSession.cs b/Hohoema.Core/Models/Player/IStreamingSession.cs index cc39b111..32500de5 100644 --- a/Hohoema.Core/Models/Player/IStreamingSession.cs +++ b/Hohoema.Core/Models/Player/IStreamingSession.cs @@ -9,5 +9,5 @@ namespace Hohoema.Models.Player; public interface IStreamingSession : IDisposable { NicoVideoQuality Quality { get; } - Task StartPlayback(MediaPlayer player, TimeSpan initialPosition = default); + Task SetMediaSourceToPlayer(MediaPlayer player, TimeSpan initialPosition = default, bool play = true); } \ No newline at end of file diff --git a/Hohoema.Core/Models/Player/Video/VideoStreamingSession/VideoStreamingSession.cs b/Hohoema.Core/Models/Player/Video/VideoStreamingSession/VideoStreamingSession.cs index 20fa6da8..77facd7b 100644 --- a/Hohoema.Core/Models/Player/Video/VideoStreamingSession/VideoStreamingSession.cs +++ b/Hohoema.Core/Models/Player/Video/VideoStreamingSession/VideoStreamingSession.cs @@ -43,7 +43,7 @@ private void _videoSessionOwnership_ReturnOwnershipRequested(object sender, Even StopStreamingFromOwnerShipReturned?.Invoke(this, e); } - public async Task StartPlayback(MediaPlayer player, TimeSpan initialPosition = default) + public async Task SetMediaSourceToPlayer(MediaPlayer player, TimeSpan initialPosition = default, bool play = true) { // Note: HTML5プレイヤー移行中のFLV動画に対するフォールバック処理 // サムネではContentType=FLV,SWFとなっていても、 @@ -147,8 +147,10 @@ public async Task StartPlayback(MediaPlayer player, TimeSpan initialPosition = d _PlayingMediaPlayer.PlaybackSession.Position = initialPosition; OnStartStreaming(); - - _PlayingMediaPlayer.Play(); + if (play) + { + _PlayingMediaPlayer.Play(); + } } else { diff --git a/Hohoema.Core/Models/Playlist/HohoemaPlaylistPlayer.cs b/Hohoema.Core/Models/Playlist/HohoemaPlaylistPlayer.cs index 67f4b2f9..753e7fd6 100644 --- a/Hohoema.Core/Models/Playlist/HohoemaPlaylistPlayer.cs +++ b/Hohoema.Core/Models/Playlist/HohoemaPlaylistPlayer.cs @@ -544,6 +544,7 @@ public async Task ChangeQualityAsync(NicoVideoQualityEntity qualityEntity) IStreamingSession videoSession; if (_videoSessionDisposable is DomandStreamingSession dommandSession) { + _videoSessionDisposable?.Dispose(); videoSession = await CurrentPlayingSession.VideoSessionProvider.CreateVideoSessionAsync(qualityEntity); } else @@ -560,7 +561,7 @@ public async Task ChangeQualityAsync(NicoVideoQualityEntity qualityEntity) _videoSessionDisposable = videoSession; - await videoSession.StartPlayback(_mediaPlayer, currentPosition ?? TimeSpan.Zero); + await videoSession.SetMediaSourceToPlayer(_mediaPlayer, currentPosition ?? TimeSpan.Zero); _mediaPlayer.PlaybackSession.PlaybackRate = lastPlaybackRate; _playerSettings.DefaultVideoQualityId = qualityEntity.QualityId; @@ -575,11 +576,10 @@ private void StopPlaybackMedia() TimeSpan endPosition = _mediaPlayer.PlaybackSession.Position; VideoId? videoId = CurrentPlaylistItem?.VideoId; + _mediaPlayer.Source = null; _videoSessionDisposable?.Dispose(); _videoSessionDisposable = null; CurrentPlayingSession = null; - _mediaPlayer.Pause(); - _mediaPlayer.Source = null; ClearCurrentContent(); if (prevSource != null && videoId.HasValue) @@ -731,6 +731,7 @@ private async Task UpdatePlayingMediaAsync(IVideoContent item, TimeSpan? s { Guard.IsNotNull(item, nameof(item)); + IStreamingSession? videoSession = null; try { PlayingOrchestrateResult result = await _videoStreamingOriginOrchestrator.CreatePlayingOrchestrateResultAsync(item.VideoId); @@ -747,10 +748,9 @@ private async Task UpdatePlayingMediaAsync(IVideoContent item, TimeSpan? s qualityEntity = AvailableQualities.SkipWhile(x => !x.IsAvailable).First(); } - IStreamingSession videoSession = await result.VideoSessionProvider.CreateVideoSessionAsync(qualityEntity); + videoSession = await result.VideoSessionProvider.CreateVideoSessionAsync(qualityEntity); _videoSessionDisposable = videoSession; - await videoSession.StartPlayback(_mediaPlayer, startPosition ?? TimeSpan.Zero); _mediaPlayer.PlaybackSession.PlaybackRate = _playerSettings.PlaybackRate; CurrentQuality = AvailableQualities.First(x => x.Quality == videoSession.Quality); @@ -761,9 +761,6 @@ private async Task UpdatePlayingMediaAsync(IVideoContent item, TimeSpan? s NowPlayingWithCache = videoSession is CachedVideoStreamingSession; - // メディア再生成功時のメッセージを飛ばす - _ = _messenger.Send(new PlaybackStartedMessage(new(this, CurrentPlaylistId, item.VideoId, videoSession.Quality, _mediaPlayer.PlaybackSession))); - _mediaPlayer.PlaybackSession.PlaybackStateChanged -= PlaybackSession_PlaybackStateChanged; _mediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged; @@ -791,10 +788,20 @@ await _dispatcherQueue.EnqueueAsync(async () => _smtc.ButtonPressed -= _smtc_ButtonPressed; _smtc.ButtonPressed += _smtc_ButtonPressed; + // 自動で再生開始せず、アプリ側で制御してもらう + await videoSession.SetMediaSourceToPlayer(_mediaPlayer, startPosition ?? TimeSpan.Zero, false); + + // メディア再生成功時のメッセージを飛ばす + _ = _messenger.Send(new PlaybackStartedMessage(new(this, CurrentPlaylistId, item.VideoId, videoSession.Quality, _mediaPlayer.PlaybackSession))); + return true; } catch (Exception) { + videoSession?.Dispose(); + _mediaPlayer.PlaybackSession.PlaybackStateChanged -= PlaybackSession_PlaybackStateChanged; + _smtc.ButtonPressed -= _smtc_ButtonPressed; + StopPlaybackMedia(); _ = _messenger.Send(new PlaybackFailedMessage(new(this, CurrentPlaylistId, item.VideoId, PlayingOrchestrateFailedReason.Unknown))); throw; diff --git a/Hohoema.sln b/Hohoema.sln index 1c00af68..77b1efce 100644 --- a/Hohoema.sln +++ b/Hohoema.sln @@ -13,24 +13,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "R3.UWP", "R3.UWP\R3.UWP.csp EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|ARM = Debug|ARM Debug|ARM64 = Debug|ARM64 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|ARM = Release|ARM Release|ARM64 = Release|ARM64 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|Any CPU.ActiveCfg = Debug|x64 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|Any CPU.Build.0 = Debug|x64 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|Any CPU.Deploy.0 = Debug|x64 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|ARM.ActiveCfg = Debug|ARM - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|ARM.Build.0 = Debug|ARM - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|ARM.Deploy.0 = Debug|ARM {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|ARM64.ActiveCfg = Debug|ARM64 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|ARM64.Build.0 = Debug|ARM64 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|ARM64.Deploy.0 = Debug|ARM64 @@ -40,12 +30,6 @@ Global {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|x86.ActiveCfg = Debug|x86 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|x86.Build.0 = Debug|x86 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Debug|x86.Deploy.0 = Debug|x86 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|Any CPU.ActiveCfg = Release|x64 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|Any CPU.Build.0 = Release|x64 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|Any CPU.Deploy.0 = Release|x64 - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|ARM.ActiveCfg = Release|ARM - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|ARM.Build.0 = Release|ARM - {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|ARM.Deploy.0 = Release|ARM {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|ARM64.ActiveCfg = Release|ARM64 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|ARM64.Build.0 = Release|ARM64 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|ARM64.Deploy.0 = Release|ARM64 @@ -55,60 +39,32 @@ Global {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|x86.ActiveCfg = Release|x86 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|x86.Build.0 = Release|x86 {17BCCDA1-CE22-4306-8845-FDD7B346944D}.Release|x86.Deploy.0 = Release|x86 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|Any CPU.ActiveCfg = Debug|x64 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|Any CPU.Build.0 = Debug|x64 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|Any CPU.Deploy.0 = Debug|x64 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|ARM.ActiveCfg = Debug|ARM - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|ARM.Build.0 = Debug|ARM - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|ARM.Deploy.0 = Debug|ARM {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|ARM64.ActiveCfg = Debug|ARM64 {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|x64.ActiveCfg = Debug|x64 {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Debug|x86.ActiveCfg = Debug|x86 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|Any CPU.ActiveCfg = Release|x64 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|Any CPU.Build.0 = Release|x64 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|Any CPU.Deploy.0 = Release|x64 - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|ARM.ActiveCfg = Release|ARM - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|ARM.Build.0 = Release|ARM - {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|ARM.Deploy.0 = Release|ARM {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|ARM64.ActiveCfg = Release|ARM64 {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|ARM64.Build.0 = Release|ARM64 {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|ARM64.Deploy.0 = Release|ARM64 {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|x64.ActiveCfg = Release|x64 {D46333EA-134E-46A0-AA86-FECA2C1E74E3}.Release|x86.ActiveCfg = Release|x86 - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|ARM.ActiveCfg = Debug|ARM - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|ARM.Build.0 = Debug|ARM {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|ARM64.ActiveCfg = Debug|ARM64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|ARM64.Build.0 = Debug|ARM64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|x64.ActiveCfg = Debug|x64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|x64.Build.0 = Debug|x64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|x86.ActiveCfg = Debug|x86 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Debug|x86.Build.0 = Debug|x86 - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|Any CPU.Build.0 = Release|Any CPU - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|ARM.ActiveCfg = Release|ARM - {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|ARM.Build.0 = Release|ARM {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|ARM64.ActiveCfg = Release|ARM64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|ARM64.Build.0 = Release|ARM64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|x64.ActiveCfg = Release|x64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|x64.Build.0 = Release|x64 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|x86.ActiveCfg = Release|x86 {5877A9CA-2D3A-4B8B-86CA-D77E6D68CF98}.Release|x86.Build.0 = Release|x86 - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|ARM.ActiveCfg = Debug|ARM - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|ARM.Build.0 = Debug|ARM {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|ARM64.ActiveCfg = Debug|ARM64 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|ARM64.Build.0 = Debug|ARM64 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|x64.ActiveCfg = Debug|x64 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|x64.Build.0 = Debug|x64 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|x86.ActiveCfg = Debug|x86 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Debug|x86.Build.0 = Debug|x86 - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|Any CPU.Build.0 = Release|Any CPU - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|ARM.ActiveCfg = Release|ARM - {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|ARM.Build.0 = Release|ARM {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|ARM64.ActiveCfg = Release|ARM64 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|ARM64.Build.0 = Release|ARM64 {A90FCB00-1552-4570-94A9-A1DD9F2CEBEB}.Release|x64.ActiveCfg = Release|x64 diff --git a/Hohoema/Hohoema.csproj b/Hohoema/Hohoema.csproj index a98119bc..3eb7aa8f 100644 --- a/Hohoema/Hohoema.csproj +++ b/Hohoema/Hohoema.csproj @@ -31,7 +31,7 @@ 0 D:\tor4k\Documents\Hohoema\Packages\ True - 015B2FDB045FEC07E2DE40236A00B5DC31563AE6 + 0466F2F6C316015FB1FAE8ED719BCEAC860FC78A true diff --git a/Hohoema/Package.appxmanifest b/Hohoema/Package.appxmanifest index 80950509..25a1b35a 100644 --- a/Hohoema/Package.appxmanifest +++ b/Hohoema/Package.appxmanifest @@ -1,6 +1,6 @@  - + Hohoema diff --git a/Hohoema/Views.Player/VideoPlayerPageViewModel.cs b/Hohoema/Views.Player/VideoPlayerPageViewModel.cs index 2ee2104f..bf7af5e9 100644 --- a/Hohoema/Views.Player/VideoPlayerPageViewModel.cs +++ b/Hohoema/Views.Player/VideoPlayerPageViewModel.cs @@ -493,15 +493,12 @@ async void MediaPlayer_MediaOpened(MediaPlayer sender, object args) // コメントを更新 await _dispatcherQueue.EnqueueAsync(async () => { - sender.Pause(); - try - { - await CommentPlayer.UpdatePlayingCommentAsync(result.CommentSessionProvider); - } - finally - { - sender.Play(); - } + await CommentPlayer.UpdatePlayingCommentAsync(result.CommentSessionProvider); + + // コメント読み込み完了後に再生を開始したい + // このためにHohoemaPlaylistPlayerなどで再生開始しないように調整している + // 動画準備段階でコメント準備処理が走ると稀に映像が表示されないまま再生するケースがあった + MediaPlayer.Play(); }); } void MediaPlayer_MediaFailed(MediaPlayer sender, MediaPlayerFailedEventArgs args) diff --git a/Hohoema/Views/Extensions/MediaPlayer/MediaPlayerSetter.cs b/Hohoema/Views/Extensions/MediaPlayer/MediaPlayerSetter.cs index 9534877d..8ab774f6 100644 --- a/Hohoema/Views/Extensions/MediaPlayer/MediaPlayerSetter.cs +++ b/Hohoema/Views/Extensions/MediaPlayer/MediaPlayerSetter.cs @@ -42,6 +42,7 @@ protected override void OnAttached() { base.OnAttached(); + this.AssociatedObject.Loaded -= AssociatedObject_Loaded; this.AssociatedObject.Loaded += AssociatedObject_Loaded; } @@ -54,6 +55,7 @@ protected override void OnDetaching() private void AssociatedObject_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { + this.AssociatedObject.Loaded -= AssociatedObject_Loaded; if (MediaPlayer != null) { AssociatedObject.SetMediaPlayer(MediaPlayer);