Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mergeing Update #78

Merged
merged 5 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dimmer/AppShellMobile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:m="clr-namespace:UraniumUI.Icons.MaterialIcons;assembly=UraniumUI.Icons.MaterialIcons"
Shell.TabBarUnselectedColor="Gray"
Shell.TabBarForegroundColor="DarkSlateBlue"
Shell.TabBarBackgroundColor="#0C0E0D"
Shell.TabBarBackgroundColor="Black"
Shell.BackgroundColor="Black"
Shell.TabBarTitleColor="DarkSlateBlue"
Shell.ForegroundColor="Transparent"
Expand Down
12 changes: 12 additions & 0 deletions Dimmer/AppShellMobile.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ public AppShellMobile()
Routing.RegisterRoute(nameof(SpecificAlbumPage), typeof(SpecificAlbumPage));
Routing.RegisterRoute(nameof(AlbumPageM), typeof(AlbumPageM));
}

protected override bool OnBackButtonPressed()
{
var bmtSheet = IPlatformApplication.Current.Services.GetService<NowPlayingBtmSheet>();
if (bmtSheet.IsPresented)
{
bmtSheet.IsPresented = false;
return true;
}
return base.OnBackButtonPressed();

}
}
5 changes: 5 additions & 0 deletions Dimmer/CustomPopUpViews/SortingPopUp.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<ResourceDictionary>
<Style TargetType="Label">
<Setter Property="FontSize" Value="17"/>
<Setter Property="TextColor" Value="White"/>
</Style>

<Style TargetType="material:RadioButton">
<Setter Property="TextColor" Value="White"/>
</Style>
</ResourceDictionary>
</Border.Resources>
Expand Down
6 changes: 3 additions & 3 deletions Dimmer/Dimmer-MAUI.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
<SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
<ActiveDebugFramework>net8.0-android34.0</ActiveDebugFramework>
<ActiveDebugProfile>Pixel 5 - API 34 (Android 14.0 - API 34)</ActiveDebugProfile>
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
<DefaultDevice>pixel_5_-_api_34</DefaultDevice>
<UapAppxPackageBuildMode>SideloadOnly</UapAppxPackageBuildMode>
<AppxShowAllApps>False</AppxShowAllApps>
Expand Down
3 changes: 2 additions & 1 deletion Dimmer/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public static MauiApp CreateMauiApp()
//builder.Services.AddSingleton(FilePicker.Default);
builder.Services.AddSingleton(FileSaver.Default);

builder.Services.AddSingleton<NowPlayingSongPageBtmSheet>();
//builder.Services.AddSingleton<NowPlayingSongPageBtmSheet>();
builder.Services.AddTransient<NowPlayingBtmSheet>(); //uranium
builder.Services.AddTransient<SongMenuBtmSheet>();

/* Registering the DataAccess Services */
Expand Down
22 changes: 17 additions & 5 deletions Dimmer/Platforms/Android/MAudioLib/MediaPlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Activity = Android.App.Activity;
using Android.Content.PM;
using System.Diagnostics;
using static Android.Icu.Text.Transliterator;

namespace Dimmer_MAUI.Platforms.Android.MAudioLib;

Expand Down Expand Up @@ -174,9 +175,16 @@ private void InitMediaSession()
/// <summary>
/// Intializes the player.
/// </summary>
public void DoInitialInitialization()
{
InitializePlayer();
InitMediaSession();

}
private void InitializePlayer()
{
mediaPlayer = new MediaPlayer();

mediaPlayer.SetAudioAttributes(new AudioAttributes.Builder()
.SetContentType(AudioContentType.Music)
.SetUsage(AudioUsageKind.Media).Build());
Expand Down Expand Up @@ -227,10 +235,8 @@ public bool OnError(MediaPlayer mp, MediaError what, int extra)

public void OnPrepared(MediaPlayer mp)
{
var pos = (int)IPlatformApplication.Current.Services.GetService<HomePageVM>().CurrentPositionInSeconds * 100;
mp.SeekTo(pos);
mp.SeekTo(positionInMs);
mp.Start();

UpdatePlaybackState(PlaybackStateCode.Playing);
Console.WriteLine("Step 9 Prepared");
}
Expand Down Expand Up @@ -298,13 +304,16 @@ public object Cover
/// <summary>
/// Intializes the player.
/// </summary>
int positionInMs = 0;
public async Task Play(int position = 0)
{
Console.WriteLine("Step 6 Play method from mediaplayerservice");
positionInMs = position;
if (mediaPlayer != null && MediaPlayerState == PlaybackStateCode.Paused)
{
//We are simply paused so just start again
Console.WriteLine("Not null");

Console.WriteLine("From Play Seeking to " + position);
mediaPlayer.SeekTo(position);

mediaPlayer.Start();
Expand Down Expand Up @@ -338,6 +347,7 @@ public async Task Play(int position = 0)
isCurrentEpisode = true;

await PrepareAndPlayMediaPlayerAsync();

}

private async Task PrepareAndPlayMediaPlayerAsync()
Expand Down Expand Up @@ -469,7 +479,8 @@ public async Task Seek(int position = 0, PlaybackStateCode playbackStateCode = P
{
await Task.Run(() =>
{
mediaPlayer?.SeekTo(position);
Console.WriteLine("From Seek Seeking to "+position);
mediaPlayer?.SeekTo(position);
UpdatePlaybackState(MediaPlayerState, position);
});
}
Expand Down Expand Up @@ -842,6 +853,7 @@ public override async void OnStop()
public override async void OnSeekTo(long pos)
{
await mediaPlayerService.GetMediaPlayerService().Seek((int)pos);
Console.WriteLine("From OnSeek Seeking to " + pos);
base.OnSeekTo(pos);
}

Expand Down
19 changes: 14 additions & 5 deletions Dimmer/Platforms/Android/MAudioLib/NativeAudioService.android.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Stream = Android.Media.Stream;
using Android.Media;
using Dimmer_MAUI.Platforms.Android.CurrentActivity;
using System.Diagnostics;

namespace Dimmer_MAUI.Platforms.Android.MAudioLib;

Expand All @@ -15,6 +16,7 @@ public class NativeAudioService : INativeAudioService
//private MediaPlayer mediaPlayer => instance != null &&
// instance.Binder.GetMediaPlayerService() != null ?
// instance.Binder.GetMediaPlayerService().mediaPlayer : null;
MediaPlay CurrentMedia { get; set; }
private MediaPlayer mediaPlayer
{
get
Expand Down Expand Up @@ -46,7 +48,7 @@ public double Duration
get
{
if (mediaPlayer == null)
Console.WriteLine("media player is null");
Console.WriteLine("media player is null in duration");
return mediaPlayer?.Duration / 1000 ?? 0;
}
}
Expand Down Expand Up @@ -96,7 +98,7 @@ public Task PauseAsync()

public async Task PlayAsync(double position = 0, bool IsFromUser = false)
{
var posInMs = (int)(position * Duration * 1000);
var posInMs = (int)(position * CurrentMedia.DurationInMs);
await instance.Binder.GetMediaPlayerService().Play((int)posInMs);
}

Expand Down Expand Up @@ -159,6 +161,7 @@ public Task DisposeAsync()

public async Task InitializeAsync(MediaPlay media)
{
CurrentMedia = media;
if (instance == null)
{
var activity = CrossCurrentActivity.Current;
Expand All @@ -169,9 +172,15 @@ public async Task InitializeAsync(MediaPlay media)
instance.Binder.GetMediaPlayerService().isCurrentEpisode = false;
instance.Binder.GetMediaPlayerService().UpdatePlaybackStateStopped();
}

instance.Binder.GetMediaPlayerService().mediaPlay = media;
if (instance.Binder.GetMediaPlayerService().mediaPlayer == null)
{
instance.Binder.GetMediaPlayerService().DoInitialInitialization();
}
if (instance.Binder.GetMediaPlayerService().mediaPlayer == null)
Console.WriteLine("MediaPlayer is null");
{
Debug.WriteLine("Let me know");
}
instance.Binder.GetMediaPlayerService().IsPlayingChanged += IsPlayingChanged;
instance.Binder.GetMediaPlayerService().TaskPlayEnded += PlayEnded;
instance.Binder.GetMediaPlayerService().TaskPlayNext += PlayNext;
Expand All @@ -193,7 +202,7 @@ public async Task InitializeAsync(MediaPlay media)
};
//if(media.Image!=null) instance.Binder.GetMediaPlayerService().Cover= await GetImageBitmapFromUrl(media.Image);
//else instance.Binder.GetMediaPlayerService().Cover = null;
instance.Binder.GetMediaPlayerService().mediaPlay = media;

}

}
5 changes: 3 additions & 2 deletions Dimmer/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ protected override void OnCreate(Bundle? savedInstanceState)
base.OnCreate(savedInstanceState);
//Window.SetStatusBarColor(Android.Graphics.Color.ParseColor("#000000"));
Window.SetStatusBarColor(Android.Graphics.Color.Black);
Window.SetNavigationBarColor(Android.Graphics.Color.ParseColor("#0C0E0D"));
Window.SetNavigationBarColor(Android.Graphics.Color.Black);
//Window.SetNavigationBarColor(Android.Graphics.Color.ParseColor("#0C0E0D"));
CrossCurrentActivity.Current.Init(this, savedInstanceState);

NotificationHelper.CreateNotificationChannel(Platform.AppContext);
if (mediaPlayerServiceConnection is null)
{
Expand Down
16 changes: 16 additions & 0 deletions Dimmer/Properties/PublishProfiles/MSIX-win10-x64.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishDir>bin\Debug\net8.0-android34.0\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<Platform>Any CPU</Platform>
<Configuration>Debug</Configuration>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<SelfContained>True</SelfContained>
<PublishAppxPackage>true</PublishAppxPackage>
<AppxPackageDir>bin\Debug\net8.0-windows10.0.19041.0\win10-x64\AppPackages\</AppxPackageDir>
</PropertyGroup>
</Project>
41 changes: 26 additions & 15 deletions Dimmer/Utilities/Services/PlaybackUtilsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,11 @@ public async Task<bool> LoadSongsFromFolder(List<string> folderPaths)
// await SongsMgtService.AddSongBatchAsync(songs!);
//}

List<SongsModel> dbSongs = songs.Select(song => new SongsModel(song)).ToList();

List<SongsModel> dbSongs = new();
if (songs != null)
{
dbSongs = songs.Select(song => new SongsModel(song)).ToList();
}
ArtistsMgtService.AddSongToArtistWithArtistIDAndAlbum(allArtists, allAlbums, allLinks, dbSongs);

var songss = SongsMgtService.AllSongs.Concat(songs).ToObservableCollection();
Expand Down Expand Up @@ -587,6 +590,7 @@ public async Task<bool> PlaySelectedSongsOutsideAppAsync(string[] filePaths)

return true;
}
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); // Initialize with a count of 1

public async Task<bool> PlaySongAsync(SongsModelView? song = null, int currentQueue = 0,
ObservableCollection<SongsModelView>? currentList = null, double lastPositionPercentage = 0, int repeatMode = 0, int repeatMaxCount = 0)
Expand Down Expand Up @@ -656,20 +660,27 @@ public async Task<bool> PlaySongAsync(SongsModelView? song = null, int currentQu
_playerStateSubject.OnNext(MediaPlayerState.LyricsLoad);

//var coverImage = GetCoverImage(ObservableCurrentlyPlayingSong!.FilePath, true);

await audioService.InitializeAsync(new MediaPlay()
await _semaphore.WaitAsync();
try
{
Name = ObservableCurrentlyPlayingSong.Title,
Author = ObservableCurrentlyPlayingSong!.ArtistName!,
URL = ObservableCurrentlyPlayingSong.FilePath,
ImageBytes = coverImage,
DurationInMs = (long)(ObservableCurrentlyPlayingSong.DurationInSeconds * 1000),
});

var positionInSeconds = (double)lastPositionPercentage * ObservableCurrentlyPlayingSong.DurationInSeconds;

await audioService.PlayAsync(lastPositionPercentage, IsFromUser: true);
bugCount = 0;
// First, initialize the audio service
await audioService.InitializeAsync(new MediaPlay()
{
Name = ObservableCurrentlyPlayingSong.Title,
Author = ObservableCurrentlyPlayingSong!.ArtistName!,
URL = ObservableCurrentlyPlayingSong.FilePath,
ImageBytes = coverImage,
DurationInMs = (long)(ObservableCurrentlyPlayingSong.DurationInSeconds * 1000),
});

// Now, play the audio after initialization has completed
await audioService.PlayAsync(lastPositionPercentage, IsFromUser: true);
}
finally
{
// Release the semaphore so other tasks can proceed
_semaphore.Release();
}

_positionTimer.Start();

Expand Down
Loading