Skip to content

Commit

Permalink
Merge branch 'release/v1.6.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
tor4kichi committed Feb 26, 2024
2 parents 07662c3 + d431dae commit 81be548
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 448 deletions.
2 changes: 1 addition & 1 deletion Hohoema/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap mp uap3">
<Identity Name="18803tor4kichi.Hohoema" Publisher="CN=DFF1CEA0-5963-4197-8676-6105C5E8CE4B" Version="1.6.2.0" />
<Identity Name="18803tor4kichi.Hohoema" Publisher="CN=DFF1CEA0-5963-4197-8676-6105C5E8CE4B" Version="1.6.3.0" />
<mp:PhoneIdentity PhoneProductId="01cfd879-0a19-44a7-b5db-11bdbd13f0df" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>Hohoema</DisplayName>
Expand Down
151 changes: 73 additions & 78 deletions Hohoema/Services/Player/Videos/VideoEndedRecommendation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Hohoema.Models.Player;
using Hohoema.Models.Player.Video;
using Hohoema.Models.Playlist;
using NiconicoToolkit.NicoRepo;
using NiconicoToolkit.Video;
using NiconicoToolkit.Video.Watch;
using Reactive.Bindings;
Expand All @@ -16,6 +17,7 @@
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Windows.Media.Playback;
using Windows.System;

namespace Hohoema.Services.Player;

Expand Down Expand Up @@ -54,17 +56,15 @@ VideoWatchedRepository videoWatchedRepository
HasRecomend = new ReactiveProperty<bool>(_scheduler);

_messenger.RegisterAll(this);
}

readonly TimeSpan _endedTime = TimeSpan.FromSeconds(-1);

bool _endedProcessed;
private void PlaybackSession_PositionChanged(MediaPlaybackSession sender, object args)
{
_scheduler.Schedule(async () =>
_positionUpdateTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
_positionUpdateTimer.Interval = TimeSpan.FromMilliseconds(250);
_positionUpdateTimer.IsRepeating = true;
_positionUpdateTimer.Tick += async (t, s) =>
{
using var _ = await _lock.LockAsync(default);

var sender = _mediaPlayer.PlaybackSession;
if (sender.PlaybackState == MediaPlaybackState.None) { return; }
if (_playNext) { return; }
if (_hohoemaPlaylistPlayer.CurrentPlaylistItem == null) { return; }
Expand All @@ -73,91 +73,88 @@ private void PlaybackSession_PositionChanged(MediaPlaybackSession sender, object
bool isInsideEndedRange = sender.Position - sender.NaturalDuration > _endedTime;
bool isStopped = sender.PlaybackState == MediaPlaybackState.Paused;
IsEnded.Value = isInsideEndedRange && isStopped;

if (HasRecomend.Value) { return; }

try
if (!IsEnded.Value || _endedProcessed)
{
if (!IsEnded.Value || _endedProcessed)
{
HasRecomend.Value = HasNextVideo && IsEnded.Value;
return;
}

var currentVideoId = _hohoemaPlaylistPlayer.CurrentPlaylistItem.VideoId;
// この時点でキューから削除してしまうと、プレイヤー上のプレイリストの現在アイテムがnullになってしまう
// 他のアイテムが再生されたり、プレイヤーが閉じられたタイミングで
//
//_queuePlaylist.Remove(currentVideoId);
//_videoWatchedRepository.VideoPlayed(currentVideoId, sender.Position);

if (_playerSettings.IsPlaylistAutoMoveEnabled && await _hohoemaPlaylistPlayer.CanGoNextAsync())
{
if (await _hohoemaPlaylistPlayer.GoNextAsync())
{
return;
}
}
HasRecomend.Value = HasNextVideo && IsEnded.Value;
return;
}

// _queuePlaylistのアイテム削除後の更新がScheduler上で行われるため、アイテム更新操作が同期的にではなく
// sortablePlaylist.TotalCountが実際とズレる可能性があるため、処理完了を待つ
await Task.Delay(10);
var currentVideoId = _hohoemaPlaylistPlayer.CurrentPlaylistItem.VideoId;
// この時点でキューから削除してしまうと、プレイヤー上のプレイリストの現在アイテムがnullになってしまう
// 他のアイテムが再生されたり、プレイヤーが閉じられたタイミングで
//
//_queuePlaylist.Remove(currentVideoId);
//_videoWatchedRepository.VideoPlayed(currentVideoId, sender.Position);

if (_playerSettings.IsPlaylistLoopingEnabled
&& _hohoemaPlaylistPlayer.CurrentPlaylist is ISortablePlaylist sortablePlaylist
&& sortablePlaylist.TotalCount > 0
&& _hohoemaPlaylistPlayer.CurrentPlaylist is not QueuePlaylist
)
if (_playerSettings.IsPlaylistAutoMoveEnabled && await _hohoemaPlaylistPlayer.CanGoNextAsync())
{
if (await _hohoemaPlaylistPlayer.GoNextAsync())
{
if (await _hohoemaPlaylistPlayer.PlayAsync(_hohoemaPlaylistPlayer.CurrentPlaylist, _hohoemaPlaylistPlayer.CurrentPlaylistSortOption))
{
return;
}
return;
}
}

// _queuePlaylistのアイテム削除後の更新がScheduler上で行われるため、アイテム更新操作が同期的にではなく
// sortablePlaylist.TotalCountが実際とズレる可能性があるため、処理完了を待つ
await Task.Delay(10);

if (_hohoemaPlaylistPlayer.CurrentPlaylistItem == null && _videoRelatedContents?.NextVideo != null)
if (_playerSettings.IsPlaylistLoopingEnabled
&& _hohoemaPlaylistPlayer.CurrentPlaylist is ISortablePlaylist sortablePlaylist
&& sortablePlaylist.TotalCount > 0
&& _hohoemaPlaylistPlayer.CurrentPlaylist is not QueuePlaylist
)
{
if (await _hohoemaPlaylistPlayer.PlayAsync(_hohoemaPlaylistPlayer.CurrentPlaylist, _hohoemaPlaylistPlayer.CurrentPlaylistSortOption))
{
_endedProcessed = true;
HasNextVideo = _videoRelatedContents?.NextVideo != null;
NextVideoTitle = _videoRelatedContents?.NextVideo?.Label;
HasRecomend.Value = HasNextVideo && IsEnded.Value;
return;
}
}

if (_series?.Video.Next is not null and var nextVideo)
{
NextVideoTitle = nextVideo.Title;
HasRecomend.Value = true;
HasNextVideo = true;

Debug.WriteLine("シリーズ情報から次の動画を提示: " + nextVideo.Title);
return;
}
if (_hohoemaPlaylistPlayer.CurrentPlaylistItem == null && _videoRelatedContents?.NextVideo != null)
{
_endedProcessed = true;
HasNextVideo = _videoRelatedContents?.NextVideo != null;
NextVideoTitle = _videoRelatedContents?.NextVideo?.Label;
HasRecomend.Value = HasNextVideo && IsEnded.Value;
return;
}

if (TryPlaylistEndActionPlayerClosed())
{
HasRecomend.Value = HasNextVideo && IsEnded.Value;
_endedProcessed = true;
return;
}
if (_series?.Video.Next is not null and var nextVideo)
{
NextVideoTitle = nextVideo.Title;
HasRecomend.Value = true;
HasNextVideo = true;

if (_currentVideoDetail != null)
{
var relatedVideos = await _relatedVideoContentsAggregator.GetRelatedContentsAsync(_currentVideoDetail);
_videoRelatedContents = relatedVideos;
HasNextVideo = _videoRelatedContents.NextVideo != null;
NextVideoTitle = _videoRelatedContents.NextVideo?.Label;
HasRecomend.Value = HasNextVideo && IsEnded.Value;
Debug.WriteLine("シリーズ情報から次の動画を提示: " + nextVideo.Title);
return;
}

Debug.WriteLine("動画情報から次の動画を提示: " + NextVideoTitle);
}
if (TryPlaylistEndActionPlayerClosed())
{
HasRecomend.Value = HasNextVideo && IsEnded.Value;
_endedProcessed = true;
return;
}
finally

if (_currentVideoDetail != null)
{
_videoRelatedContents ??= await _relatedVideoContentsAggregator.GetRelatedContentsAsync(_currentVideoDetail);
HasNextVideo = _videoRelatedContents.NextVideo != null;
NextVideoTitle = _videoRelatedContents.NextVideo?.Label;
HasRecomend.Value = HasNextVideo && IsEnded.Value;

Debug.WriteLine("動画情報から次の動画を提示: " + NextVideoTitle);
}
});
};
}

readonly TimeSpan _endedTime = TimeSpan.FromSeconds(-1);

bool _endedProcessed;

public async void Receive(PlaybackStartedMessage message)
{
Expand All @@ -177,16 +174,14 @@ public async void Receive(PlaybackStartedMessage message)
_endedProcessed = false;
HasRecomend.Value = false;
_currentVideoDetail = null;

_mediaPlayer.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
_mediaPlayer.PlaybackSession.PositionChanged += PlaybackSession_PositionChanged;
_positionUpdateTimer.Start();
}

public async void Receive(PlaybackStopedMessage message)
{
using var _ = await _lock.LockAsync(default);

_mediaPlayer.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
_positionUpdateTimer.Stop();

var data = message.Value;
_queuePlaylist.Remove(data.VideoId);
Expand All @@ -198,7 +193,7 @@ public async void Receive(PlaybackFailedMessage message)
{
using var _ = await _lock.LockAsync(default);

_mediaPlayer.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
_positionUpdateTimer.Stop();

var data = message.Value;
_failedVideoId = data.VideoId;
Expand All @@ -211,9 +206,8 @@ public async void Dispose()
using var _ = await _lock.LockAsync(default);

_messenger.UnregisterAll(this);
_mediaPlayer.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;

_disposables.Dispose();
_positionUpdateTimer.Stop();
}

bool TryPlaylistEndActionPlayerClosed()
Expand All @@ -239,7 +233,7 @@ bool TryPlaylistEndActionPlayerClosed()
}


VideoRelatedContents _videoRelatedContents;
VideoRelatedContents? _videoRelatedContents;

private readonly MediaPlayer _mediaPlayer;
private readonly IMessenger _messenger;
Expand All @@ -251,6 +245,7 @@ bool TryPlaylistEndActionPlayerClosed()
private readonly AppearanceSettings _appearanceSettings;
private readonly HohoemaPlaylistPlayer _hohoemaPlaylistPlayer;
private readonly VideoWatchedRepository _videoWatchedRepository;
private readonly DispatcherQueueTimer _positionUpdateTimer;

public ReactiveProperty<bool> IsEnded { get; }

Expand Down
5 changes: 4 additions & 1 deletion Hohoema/ViewModels/HohoemaListingPageViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected override async Task<IEnumerable<ITEM_VM>> LoadDataAsync(CancellationTo
public AdvancedCollectionView? ItemsView { get; private set; }

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanRefresh))]
private bool _nowLoading;

partial void OnNowLoadingChanged(bool value)
Expand Down Expand Up @@ -261,7 +262,9 @@ private void OnLodingItemError(Exception e)
_logger.ZLogError(e, "failed on incremental loadingItems.");
}

[RelayCommand]
public bool CanRefresh => !NowLoading;

[RelayCommand(CanExecute = nameof(CanRefresh))]
protected void ResetList()
{
_dispatcherQueue.TryEnqueue(() =>
Expand Down
2 changes: 1 addition & 1 deletion Hohoema/Views.Niconico/Search/SearchResultKeywordPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</AppBarButton>

<AppBarButton x:Name="SelectionToggleButton" Icon="List" Label="{i18nExt:Localize Key=Select}" Command="{x:Bind _vm.SelectionModeToggleCommand}" />
<AppBarButton x:Name="RefreshButton" Label="{i18nExt:Localize Key=Refresh}" Icon="Refresh" Command="{x:Bind _vm.ResetListCommand}" IsEnabled="{x:Bind _vm.CanChangeSort, Mode=OneWay}" VerticalAlignment="Center"></AppBarButton>
<AppBarButton x:Name="RefreshButton" Label="{i18nExt:Localize Key=Refresh}" Icon="Refresh" Command="{x:Bind _vm.ResetListCommand}" VerticalAlignment="Center"></AppBarButton>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
Label="{i18nExt:Localize Key=Refresh}"
Icon="Refresh"
Command="{x:Bind _vm.ResetListCommand}"
IsEnabled="{x:Bind _vm.CanChangeSort, Mode=OneWay}"
VerticalAlignment="Center"
>
</AppBarButton>
Expand Down
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
Loading

0 comments on commit 81be548

Please sign in to comment.