Skip to content

Commit

Permalink
動画視聴開始時のコメント読み込みを映像準備完了後に順列的に実行するようにしてスムーズに再生開始するよう調整。
Browse files Browse the repository at this point in the history
  • Loading branch information
tor4kichi committed Feb 26, 2024
1 parent 1956f18 commit d431dae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Hohoema/Views.Player/VideoPlayerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
>

<!-- 映像表示 -->
<MediaPlayerElement x:Name="MediaPlayerElement" AutoPlay="True">
<MediaPlayerElement x:Name="MediaPlayerElement" AutoPlay="False">
<i:Interaction.Behaviors>
<mybehavior:MediaPlayerSetter MediaPlayer="{x:Bind _vm.MediaPlayer}" />
<mybehavior:MediaPlayerElementContentHeightGetter ContentHeight="{x:Bind CommentRederer.Height, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Expand Down
48 changes: 38 additions & 10 deletions Hohoema/Views.Player/VideoPlayerPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using Hohoema.Views.Player;
using I18NPortable;
using Microsoft.Extensions.Logging;
using Microsoft.Toolkit.Uwp;
using NiconicoToolkit.Video;
using NiconicoToolkit.Video.Watch;
using Reactive.Bindings;
Expand All @@ -40,6 +41,7 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using Windows.Media.Playback;
using Windows.System;
using ZLogger;

namespace Hohoema.ViewModels.Player;
Expand Down Expand Up @@ -100,6 +102,7 @@ public VideoPlayerPageViewModel(
RelatedVideosSidePaneContentViewModel relatedVideosSidePaneContentViewModel
)
{
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
_logger = loggerFactory.CreateLogger<VideoPlayerPageViewModel>();
CurrentPlayerDisplayView = appearanceSettings
.ObserveProperty(x => x.PlayerDisplayView)
Expand Down Expand Up @@ -210,6 +213,7 @@ RelatedVideosSidePaneContentViewModel relatedVideosSidePaneContentViewModel

}

private readonly DispatcherQueue _dispatcherQueue;
private readonly ILogger<VideoPlayerPageViewModel> _logger;

public ReadOnlyReactivePropertySlim<PlayerDisplayView> CurrentPlayerDisplayView { get; }
Expand Down Expand Up @@ -395,19 +399,19 @@ public override void OnNavigatedTo(INavigationParameters parameters)
base.OnNavigatedTo(parameters);

_hohoemaPlaylistPlayer.ObserveProperty(x => x.CurrentQuality)
.Subscribe(quality => _scheduler.Schedule(() => CurrentQuality = quality))
.Subscribe(quality => _dispatcherQueue.TryEnqueue(() => CurrentQuality = quality))
.AddTo(_navigationDisposables);

_hohoemaPlaylistPlayer.ObserveProperty(x => x.CurrentPlaylist)
.Subscribe(playlist => _scheduler.Schedule(() => CurrentPlaylist = playlist))
.Subscribe(playlist => _dispatcherQueue.TryEnqueue(() => CurrentPlaylist = playlist))
.AddTo(_navigationDisposables);

_hohoemaPlaylistPlayer.ObserveProperty(x => x.CurrentPlaylistItem)
.Subscribe(item =>
{
if (item == null) { return; }

_scheduler.ScheduleAsync(async (s, ct) =>
_dispatcherQueue.TryEnqueue(() =>
{
try
{
Expand Down Expand Up @@ -436,8 +440,6 @@ public override void OnNavigatedTo(INavigationParameters parameters)
{
CommentPlayer.ClearCurrentSession();

MediaPlayer.AutoPlay = true;

VideoId = item.VideoId;

var result = _hohoemaPlaylistPlayer.CurrentPlayingSession;
Expand All @@ -457,9 +459,6 @@ public override void OnNavigatedTo(INavigationParameters parameters)
CurrentQuality = _hohoemaPlaylistPlayer.CurrentQuality;
NowPlayingWithCache = _hohoemaPlaylistPlayer.NowPlayingWithCache;

// コメントを更新
await CommentPlayer.UpdatePlayingCommentAsync(result.CommentSessionProvider);

VideoContent = VideoInfo;
OnPropertyChanged(nameof(VideoContent));

Expand All @@ -482,6 +481,35 @@ public override void OnNavigatedTo(INavigationParameters parameters)
{
SetSidePaneViewModel(PlayerSidePaneContentType.Comment);
}

MediaPlayer.MediaOpened -= MediaPlayer_MediaOpened;
MediaPlayer.MediaFailed -= MediaPlayer_MediaFailed;
MediaPlayer.MediaOpened += MediaPlayer_MediaOpened;
MediaPlayer.MediaFailed += MediaPlayer_MediaFailed;
async void MediaPlayer_MediaOpened(MediaPlayer sender, object args)
{
MediaPlayer.MediaOpened -= MediaPlayer_MediaOpened;
MediaPlayer.MediaFailed -= MediaPlayer_MediaFailed;
// コメントを更新
await _dispatcherQueue.EnqueueAsync(async () =>
{
sender.Pause();
try
{
await CommentPlayer.UpdatePlayingCommentAsync(result.CommentSessionProvider);
}
finally
{
sender.Play();
}
});
}
void MediaPlayer_MediaFailed(MediaPlayer sender, MediaPlayerFailedEventArgs args)
{
MediaPlayer.MediaOpened -= MediaPlayer_MediaOpened;
MediaPlayer.MediaFailed -= MediaPlayer_MediaFailed;
}

}
catch (Exception ex)
{
Expand All @@ -493,9 +521,9 @@ public override void OnNavigatedTo(INavigationParameters parameters)

App.Current.Resuming += Current_Resuming;
App.Current.Suspending += Current_Suspending;
}
}




//private void CheckDeleted(VideoIdSearchSingleResponse res)
//{
Expand Down

0 comments on commit d431dae

Please sign in to comment.