From: aman.jeph Date: Tue, 12 Oct 2021 12:25:24 +0000 (+0530) Subject: Implemented NUI Context for Main Thread Invocationa and Updated Player ErrorOccurred... X-Git-Tag: submit/tizen/20211109.094344~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=61928324ca27fa2147e04a2d93217898b81897f2;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Implemented NUI Context for Main Thread Invocationa and Updated Player ErrorOccurred event Fixed theme issues for tabs Change-Id: If764291eb9f819375f7482455e45230f0c532c7e Signed-off-by: aman.jeph --- diff --git a/music-player/Common/NUISynchronizationContext.cs b/music-player/Common/NUISynchronizationContext.cs new file mode 100755 index 0000000..074dd7a --- /dev/null +++ b/music-player/Common/NUISynchronizationContext.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace MusicPlayer.Common +{ + public static class NUISynchronizationContext + { + private static SynchronizationContext context; + + public static void Initialize() + { + context = SynchronizationContext.Current; + } + + public static void InvokeOnNUIThread(SendOrPostCallback callback, object arg) + { + context?.Post(callback, arg); + } + } +} diff --git a/music-player/Core/ColorExtractor.cs b/music-player/Core/ColorExtractor.cs old mode 100644 new mode 100755 index db4a86d..0f32f94 --- a/music-player/Core/ColorExtractor.cs +++ b/music-player/Core/ColorExtractor.cs @@ -15,7 +15,7 @@ namespace MusicPlayer.Core private static Palette GeneratePalette(string imagePath) { - PixelBuffer pixelBuffer = ImageLoading.LoadImageFromFile(imagePath); + PixelBuffer pixelBuffer = ImageLoader.LoadImageFromFile(imagePath); if(pixelBuffer == null) { Tizen.Log.Error(AppConstants.LogTag, "Pixel buffer is null"); diff --git a/music-player/Core/MusicPlayer.cs b/music-player/Core/MusicPlayer.cs old mode 100644 new mode 100755 index 30942d5..0237cb3 --- a/music-player/Core/MusicPlayer.cs +++ b/music-player/Core/MusicPlayer.cs @@ -71,9 +71,10 @@ namespace MusicPlayer.Core { Tizen.Log.Error("MusicPlayer", "InvalidOperationException: "+ex.Message); } - finally // TODO do we really need this + catch(Exception ex) { - //DisposePlayer(); + Tizen.Log.Error(AppConstants.LogTag, "Exception : " + ex.Message); + EmitErrorEvent(ex.Message); } } @@ -170,11 +171,44 @@ namespace MusicPlayer.Core Tizen.Log.Error(AppConstants.LogTag, "Playback completed"); } - // TODO this event is called on a differnt thread..need to handle it + private void EmitErrorEvent(object o) + { + string error = (string)o; + PlayerEvent.Invoke(this, new PlayerEventArgs(EventType.Error, error)); + } + private void OnErrorOccurred(object sender, PlayerErrorOccurredEventArgs e) { - PlayerEvent.Invoke(this, new PlayerEventArgs(EventType.Error, e.Error.ToString())); - Tizen.Log.Error(AppConstants.LogTag, "Error Occurred: " + e.Error.ToString()); + Tizen.Log.Debug(AppConstants.LogTag, "ThreadId: " + System.Threading.Thread.CurrentThread.ManagedThreadId+ "Error Occured: "+e.Error.ToString()); + System.Threading.SendOrPostCallback errorEventCallback = new System.Threading.SendOrPostCallback(EmitErrorEvent); + NUISynchronizationContext.InvokeOnNUIThread(errorEventCallback, GetErrorDescription(e.Error)); + } + + private string GetErrorDescription(PlayerError error) + { + string errorDesc = "Unknown error encountered"; + switch (error) + { + case PlayerError.NoSuchFile: + errorDesc = "File doesn't exists or invalid file"; + break; + case PlayerError.InternalError: + errorDesc = "Player internal error encountered"; + break; + case PlayerError.NoSpaceOnDevice: + errorDesc = "Not enough space on device"; + break; + case PlayerError.NotSupportedFile: + errorDesc = "File type not supported"; + break; + case PlayerError.InvalidUri: + errorDesc = "File path is not valid"; + break; + case PlayerError.AudioCodecNotSupported: + errorDesc = "Audio codec not supported"; + break; + } + return errorDesc; } } } diff --git a/music-player/MusicPlayer.cs b/music-player/MusicPlayer.cs index 4bcbccd..92fdad5 100755 --- a/music-player/MusicPlayer.cs +++ b/music-player/MusicPlayer.cs @@ -17,6 +17,10 @@ namespace MusicPlayer { Tizen.Log.Info(AppConstants.LogTag, "OnCreate statrted"); base.OnCreate(); + + //Initlize NUISynchronizationContext + NUISynchronizationContext.Initialize(); + Window window = Window.Instance; window.BackgroundColor = Color.White; Size2D size = window.Size; diff --git a/music-player/ViewModels/PlayerViewModel.cs b/music-player/ViewModels/PlayerViewModel.cs index 4f062bb..6541b40 100755 --- a/music-player/ViewModels/PlayerViewModel.cs +++ b/music-player/ViewModels/PlayerViewModel.cs @@ -336,6 +336,10 @@ namespace MusicPlayer.ViewModels { PlayNext(); } + else if(e.Type == EventType.Error) + { + Tizen.Log.Error(AppConstants.LogTag, "ThreadId: " + System.Threading.Thread.CurrentThread.ManagedThreadId + ", Error Occured: " + e.Description); + } } private void PlayNext() diff --git a/music-player/Views/BaseView.cs b/music-player/Views/BaseView.cs index b78f120..8b4daae 100755 --- a/music-player/Views/BaseView.cs +++ b/music-player/Views/BaseView.cs @@ -82,21 +82,12 @@ namespace MusicPlayer.Views FlexLayout.SetFlexGrow(contentView, 1); FlexLayout.SetFlexShrink(contentView, 1); - tabs = new Tab() + tabs = new Tab("Tabs") { ThemeChangeSensitive = true, Size2D = new Size2D(Window.Instance.Size.Width, 84), WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = 84, - UnderLineBackgroundColor = Color.Blue, - UnderLineSize = new Size2D(1, 3), - PointSize = 25, - BackgroundColor = Color.White, - }; - tabs.TextColorSelector = new ColorSelector - { - Normal = Color.Black, - Selected = Color.Magenta, }; base.Add(tabs); for(int i = 0; i<4; ++i) diff --git a/music-player/res/themes/dark.xaml b/music-player/res/themes/dark.xaml index c2e9b7e..07bf468 100755 --- a/music-player/res/themes/dark.xaml +++ b/music-player/res/themes/dark.xaml @@ -181,4 +181,13 @@ Id="LightTheme"> + + + + + + + + + \ No newline at end of file diff --git a/music-player/res/themes/light.xaml b/music-player/res/themes/light.xaml index b8c681b..5b9c38c 100755 --- a/music-player/res/themes/light.xaml +++ b/music-player/res/themes/light.xaml @@ -181,4 +181,13 @@ Id="LightTheme"> + + + + + + + + + \ No newline at end of file diff --git a/packaging/org.tizen.MusicPlayer-1.0.0.tpk b/packaging/org.tizen.MusicPlayer-1.0.0.tpk index ed28e15..4803830 100755 Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ