Skip to content

Commit

Permalink
Improve video player functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Nov 9, 2023
1 parent e5e637a commit 5ca2f42
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using AniStream.Views.BottomSheets;
using Berry.Maui.Core;
using Berry.Maui.Core.Handlers;
using Berry.Maui.Core.Primitives;
using Bumptech.Glide;
using Com.Google.Android.Exoplayer2;
using Com.Google.Android.Exoplayer2.Audio;
Expand Down Expand Up @@ -156,6 +157,8 @@ public void UpdateSourceInfo()
playerView = handler.PlatformView.GetFirstChildOfType<StyledPlayerView>()!;
exoPlayer = (IExoPlayer)playerView.Player;
exoPlayer.AddListener(this);

SetMediaSession();
}

#region Setup
Expand Down Expand Up @@ -189,6 +192,10 @@ protected override void Dispose(bool disposing)
exoPlayer.Release();
}

MediaSession?.Release();
MediaSessionConnector?.Dispose();
MediaSession?.Dispose();

CancellationTokenSource.Cancel();

Platform.CurrentActivity.RequestedOrientation = ScreenOrientation.Unspecified;
Expand All @@ -211,11 +218,8 @@ protected override void Dispose(bool disposing)
}
#endregion

public void Initialize()
private void SetMediaSession()
{
exoPlayer = (IExoPlayer)playerView.Player;
exoPlayer.AddListener(this);

try
{
MediaSession = new(Platform.CurrentActivity, "AniStreamMediaSession");
Expand All @@ -227,6 +231,20 @@ public void Initialize()
{
Snackbar.Make(e.Message).Show();
}
}

public void Initialize()
{
exoPlayer = (IExoPlayer)playerView.Player;
exoPlayer.AddListener(this);

MediaElement.StateChanged += (s, e) =>
{
if (e.NewState == MediaElementState.Paused && !playerView.IsControllerFullyVisible)
HandleController();
};

SetMediaSession();

//var bookmarkManager = new BookmarkManager("recently_watched");
//
Expand Down Expand Up @@ -285,7 +303,8 @@ public void Initialize()
}
};

if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
//if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
if (OperatingSystem.IsAndroidVersionAtLeast(26))
{
var audioAttributes = new Android.Media.AudioAttributes.Builder()
.SetUsage(Android.Media.AudioUsageKind.Media)!
Expand Down Expand Up @@ -545,7 +564,7 @@ public void Initialize()

private void DoubleTap(bool forward, MotionEvent @event) => Seek(forward, @event);

private void HandleController()
public void HandleController()
{
if (
Build.VERSION.SdkInt >= BuildVersionCodes.N
Expand Down

0 comments on commit 5ca2f42

Please sign in to comment.