From: aman.jeph Date: Wed, 19 May 2021 06:26:17 +0000 (+0530) Subject: Initial source for the MusicPlayer X-Git-Tag: submit/tizen/20210915.141722~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f10c6d773bd11a35d4f6c67785fe945ff9320620;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Initial source for the MusicPlayer Change-Id: I947b6ce92bf38712c2879e7773074e12c6a45e2f Signed-off-by: aman.jeph --- diff --git a/MediaContent/AlbumContents.cs b/MediaContent/AlbumContents.cs new file mode 100644 index 0000000..50ca286 --- /dev/null +++ b/MediaContent/AlbumContents.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Specialized; +using Tizen.Content.MediaContent; +using System.Text; + +namespace MusicPlayer.Media +{ + public static partial class Contents + { + public static OrderedDictionary GetAlbumList() + { + OrderedDictionary albumList = new OrderedDictionary(); + + SelectArguments arguments = CreateSelectArgument(MEDIA_STORAGE_TYPE_QUERY, AlbumColumns.Name + MEDIA_SORT_ORDER_ASC); + MediaDataReader dataReader = albumInfo.Select(arguments); + + while (dataReader.Read()) + { + Album info = dataReader.Current; + albumList.Add(info.Id, info); + } + Tizen.Log.Debug("MUSIC_PLAYER", "Total album retrived from database: " + albumList.Count); + dataReader.Dispose(); + return albumList; + } + + public static int GetAlbumMemberCount(int albumId) + { + return albumInfo.CountMember(albumId); + } + } +} diff --git a/MediaContent/ArtistContents.cs b/MediaContent/ArtistContents.cs new file mode 100644 index 0000000..4814bdb --- /dev/null +++ b/MediaContent/ArtistContents.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Specialized; +using System.Collections.Generic; +using System.Text; +using Tizen.Content.MediaContent; + +namespace MusicPlayer.Media +{ + public static partial class Contents + { + public static List GetArtistList() + { + List artistList = new List(); + + SelectArguments arguments = CreateSelectArgument(MEDIA_STORAGE_TYPE_QUERY, MediaInfoColumns.Artist + MEDIA_SORT_ORDER_ASC); + MediaDataReader dataReader = mediaInfo.SelectGroupBy(MediaInfoColumnKey.Artist, arguments); + + while (dataReader.Read()) + { + string info = (string)dataReader.Current; + artistList.Add(info); + } + Tizen.Log.Debug("MUSIC_PLAYER", "Total artists retrived from database: " + artistList.Count); + dataReader.Dispose(); + return artistList; + } + + public static OrderedDictionary GetAlbumListForArtist(string artistName) + { + OrderedDictionary albumList = new OrderedDictionary(); + string expression = MEDIA_STORAGE_TYPE_QUERY + "AND " + AlbumColumns.Artist + "=\"" + artistName + "\""; + SelectArguments arguments = CreateSelectArgument(expression, AlbumColumns.Name + MEDIA_SORT_ORDER_ASC); + MediaDataReader dataReader = albumInfo.Select(arguments); + + while (dataReader.Read()) + { + Album info = dataReader.Current; + albumList.Add(info.Id, info); + } + dataReader.Dispose(); + return albumList; + } + + public static int GetAlblumCountForArtist(string artistName) + { + string expression = MEDIA_STORAGE_TYPE_QUERY + "AND " + AlbumColumns.Artist + "=\"" + artistName+"\""; + CountArguments arguments = CreateCountArgument(expression); + int count = 0; + try + { + count = albumInfo.Count(arguments); + } + catch (ObjectDisposedException ex) + { + Tizen.Log.Error("MUSIC_PLAYER", "ObjectDisposedException: " + ex.Message); + } + catch (InvalidOperationException ex) + { + Tizen.Log.Error("MUSIC_PLAYER", "InvalidOperationException: " + ex.Message); + } + catch (MediaDatabaseException ex) + { + Tizen.Log.Error("MUSIC_PLAYER", "MediaDatabaseException: " + ex.Message); + } + catch (Exception ex) + { + Tizen.Log.Error("MUSIC_PLAYER", "Unknown Exception: " + ex.Message); + } + + return count; + } + } +} diff --git a/MediaContent/MediaContents.cs b/MediaContent/MediaContents.cs new file mode 100755 index 0000000..6ae5a12 --- /dev/null +++ b/MediaContent/MediaContents.cs @@ -0,0 +1,106 @@ +using System; +using Tizen.Content.MediaContent; + +namespace MusicPlayer.Media +{ + public class MusicItemUpdateEventArgs : EventArgs + { + internal MusicItemUpdateEventArgs(int pid, + OperationType operationType, MediaType mediaType, string id, string path, string mimeType) + { + ProcessId = pid; + OperationType = operationType; + Id = id; + Path = path; + MediaType = mediaType; + MimeType = mimeType; + } + public int ProcessId { get; } + + public OperationType OperationType { get; } + + public string Id { get; } + + public string Path { get; } + + public MediaType MediaType { get; } + + public string MimeType { get; } + } + + public class MusicDBUpdateEventArgs : EventArgs + { + internal MusicDBUpdateEventArgs(OperationType operationType, string id, string path) + { + OperationType = operationType; + Id = id; + Path = path; + } + + public OperationType OperationType { get; } + + public string Id { get; } + + public string Path { get; } + } + + public static partial class Contents + { + private static Database database; + private static MediaInfoCommand mediaInfo; + private static AlbumCommand albumInfo; + private static PlaylistCommand playlistInfo; + private const string MEDIA_STORAGE_TYPE_QUERY = " (( MEDIA_STORAGE_TYPE IS NOT 101 ) AND (MEDIA_TYPE = 3)) "; + private const string MEDIA_SORT_ORDER_ASC = " COLLATE NOCASE ASC "; + + public static event EventHandler MusicItemUpdate; + public static event EventHandler MusicDBUpdate; + + static Contents() + { + database = new Database(); + mediaInfo = new MediaInfoCommand(database.MediaDatabase); + albumInfo = new AlbumCommand(database.MediaDatabase); + playlistInfo = new PlaylistCommand(database.MediaDatabase); + MediaDatabase.MediaInfoUpdated += OnMediaDatabaseItemUpdate; + MediaDatabase.FolderUpdated += OnMediaDatabaseFolderUpdate; + } + + private static void OnMediaDatabaseItemUpdate(object sender, MediaInfoUpdatedEventArgs e) + { + if(e.MediaType == MediaType.Music) + { + MusicItemUpdateEventArgs item = new MusicItemUpdateEventArgs(e.ProcessId, e.OperationType, e.MediaType, + e.Id, e.Path, e.MimeType); + MusicItemUpdate?.Invoke(null, item); + } + } + + private static void OnMediaDatabaseFolderUpdate(object sender, FolderUpdatedEventArgs e) + { + MusicDBUpdateEventArgs item = new MusicDBUpdateEventArgs(e.OperationType, e.Id, e.Path); + MusicDBUpdate?.Invoke(null, item); + } + + private static SelectArguments CreateSelectArgument(string filterExpression, string sortOrder) + { + SelectArguments arguments = new SelectArguments(); + arguments.FilterExpression = filterExpression; + arguments.SortOrder = sortOrder; + return arguments; + } + + private static CountArguments CreateCountArgument(string filterExpression) + { + CountArguments arguments = new CountArguments(); + arguments.FilterExpression = filterExpression; + return arguments; + } + + public static void Dispose() + { + database.Dispose(); + } + } + +} \ No newline at end of file diff --git a/MediaContent/MediaDatabase.cs b/MediaContent/MediaDatabase.cs new file mode 100755 index 0000000..5e3ec37 --- /dev/null +++ b/MediaContent/MediaDatabase.cs @@ -0,0 +1,39 @@ +using System; +using Tizen.Content.MediaContent; + +namespace MusicPlayer.Media +{ + class Database : IDisposable + { + private MediaDatabase mediaDatabase; + + public Database() + { + mediaDatabase = new MediaDatabase(); + mediaDatabase.Connect(); + } + + private void TerminateDatabase() + { + mediaDatabase.Disconnect(); + mediaDatabase.Dispose(); + } + + ~Database() + { + TerminateDatabase(); + } + + public void Dispose() + { + TerminateDatabase(); + // This will informed gc to not call the finalize method as resources are already released. + GC.SuppressFinalize(this); + } + + public MediaDatabase MediaDatabase + { + get { return mediaDatabase; } + } + } +} diff --git a/MediaContent/PlaylistContents.cs b/MediaContent/PlaylistContents.cs new file mode 100644 index 0000000..677f574 --- /dev/null +++ b/MediaContent/PlaylistContents.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Tizen.Content.MediaContent; + +namespace MusicPlayer.Media +{ + public static partial class Contents + { + public static List GetPlaylists() + { + List playlists = new List(); + SelectArguments arguments = CreateSelectArgument(MEDIA_STORAGE_TYPE_QUERY, PlaylistColumns.Name + MEDIA_SORT_ORDER_ASC); + MediaDataReader dataReader = playlistInfo.Select(arguments); + + while(dataReader.Read()) + { + Playlist playlist = dataReader.Current; + playlists.Add(playlist); + } + Tizen.Log.Debug("MUSIC_PLAYER", "PlayLists Count : " + playlists.Count); + return playlists; + } + + public static Playlist GetPlaylistByName(string name) + { + string filterExpression = MEDIA_STORAGE_TYPE_QUERY + " AND " + PlaylistColumns.Name + "=\"" + name + "\""; + SelectArguments arguments = CreateSelectArgument(filterExpression, PlaylistColumns.Name + MEDIA_SORT_ORDER_ASC); + MediaDataReader dataReader = playlistInfo.Select(arguments); + + Playlist list = null; + while (dataReader.Read()) + { + list = dataReader.Current; + } + return list; + } + + public static Playlist GetPlaylistById(int playlistId) + { + Playlist list = null; + list = playlistInfo.Select(playlistId); + return list; + } + + } +} diff --git a/MediaContent/TrackContents.cs b/MediaContent/TrackContents.cs new file mode 100644 index 0000000..d9b57cf --- /dev/null +++ b/MediaContent/TrackContents.cs @@ -0,0 +1,25 @@ +using System.Collections.Specialized; +using Tizen.Content.MediaContent; + +namespace MusicPlayer.Media +{ + public static partial class Contents + { + public static OrderedDictionary GetTrackList() + { + OrderedDictionary mediaList = new OrderedDictionary(); + + SelectArguments argument = CreateSelectArgument(MEDIA_STORAGE_TYPE_QUERY, MediaInfoColumns.Title + MEDIA_SORT_ORDER_ASC); + MediaDataReader dataReader = mediaInfo.SelectMedia(argument); + + while (dataReader.Read()) + { + MediaInfo info = dataReader.Current; + mediaList.Add(info.Id, info); + } + Tizen.Log.Debug("MUSIC_PLAYER", "Total track retrived from database: " + mediaList.Count); + dataReader.Dispose(); + return mediaList; + } + } +} diff --git a/MusicPlayer.cs b/MusicPlayer.cs new file mode 100755 index 0000000..0da2306 --- /dev/null +++ b/MusicPlayer.cs @@ -0,0 +1,39 @@ +using System; +using Tizen.NUI; +using MusicPlayer.Views; +using MusicPlayer.Common; + +namespace MusicPlayer +{ + public class Application : NUIApplication + { + protected override void OnCreate() + { + Tizen.Log.Info("MUSIC_PLAYER", "OnCreate statrted"); + base.OnCreate(); + Window window = Window.Instance; + window.BackgroundColor = Color.White; + window.KeyEvent += OnKeyEvent; + Size2D size = window.Size; + Tizen.Log.Info("MUSIC_PLAYER", "Window Size: " + size.Width + "x" + size.Height); + + ViewManager manager = new ViewManager(Window.Instance); + } + + public void OnKeyEvent(object sender, Window.KeyEventArgs e) + { + if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == Constants.BackKeyCode || e.Key.KeyPressedName == Constants.EscapeKeyCode)) + { + Exit(); + } + } + + static void Main(string[] args) + { + Tizen.Log.Info("MUSIC_PLAYER", "Main statrted"); + var app = new Application(); + app.Run(args); + Tizen.Log.Info("MUSIC_PLAYER", "Main finished"); + } + } +} diff --git a/MusicPlayer.sln b/MusicPlayer.sln new file mode 100644 index 0000000..531db1c --- /dev/null +++ b/MusicPlayer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30804.86 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "music-player", "music-player.csproj", "{18A58E69-495D-4F9C-BA77-C969BE9D8104}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {18A58E69-495D-4F9C-BA77-C969BE9D8104}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18A58E69-495D-4F9C-BA77-C969BE9D8104}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18A58E69-495D-4F9C-BA77-C969BE9D8104}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18A58E69-495D-4F9C-BA77-C969BE9D8104}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7072B878-F218-47CE-84F8-FC9AC39798C6} + EndGlobalSection +EndGlobal diff --git a/XamlPage.xaml.cs b/XamlPage.xaml.cs new file mode 100644 index 0000000..8a08eb7 --- /dev/null +++ b/XamlPage.xaml.cs @@ -0,0 +1,14 @@ +using System; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace MusicPlayer +{ + public partial class XamlPage : View + { + public XamlPage() + { + InitializeComponent(); + } + } +} diff --git a/music-player.csproj b/music-player.csproj new file mode 100644 index 0000000..6209aa5 --- /dev/null +++ b/music-player.csproj @@ -0,0 +1,34 @@ + + + + Exe + netcoreapp3.1 + Tizen + MusicPlayer + + + + portable + + + None + + + + + + + + + + MSBuild:Compile + + + + + + + + + + diff --git a/res/layout/XamlPage.xaml b/res/layout/XamlPage.xaml new file mode 100644 index 0000000..7a54808 --- /dev/null +++ b/res/layout/XamlPage.xaml @@ -0,0 +1,9 @@ + + + + + + diff --git a/shared/res/MusicPlayer.png b/shared/res/MusicPlayer.png new file mode 100644 index 0000000..9f3cb98 Binary files /dev/null and b/shared/res/MusicPlayer.png differ diff --git a/tizen-manifest.xml b/tizen-manifest.xml new file mode 100644 index 0000000..03c8036 --- /dev/null +++ b/tizen-manifest.xml @@ -0,0 +1,14 @@ + + + + + + MusicPlayer.png + + + + + + + +