/// <summary> /// Retrieves the playlists with the <see cref="SelectArguments"/>. /// </summary> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <Playlist> Select(SelectArguments filter) { ValidateDatabase(); return(CommandHelper.Select(filter, Interop.Playlist.ForeachPlaylistFromDb, Playlist.FromHandle)); }
internal static MediaDataReader <TRecord> Select <TRecord>(SelectArguments arguments, ForeachFunc foreachFunc, Func <IntPtr, TRecord> factoryFunc) { using (var filter = QueryArguments.ToNativeHandle(arguments)) { Exception caught = null; var items = new List <TRecord>(); foreachFunc(filter, (itemHandle, _) => { try { items.Add(factoryFunc(itemHandle)); return(true); } catch (Exception e) { caught = e; return(false); } }).ThrowIfError("Failed to execute query"); if (caught != null) { throw caught; } return(new MediaDataReader <TRecord>(items)); } }
public async Task <IEnumerable <MediaItem> > GetAllVideoItemListAsync() { var itemList = new List <MediaItem>(); var selectArguments = new SelectArguments(); selectArguments.FilterExpression = VIDEO_FILTER; try { var reader = mediaInfoCommand.SelectMedia(selectArguments); while (reader.Read()) { var videoInformation = reader.Current as VideoInfo; itemList.Add( new MediaItem() { Title = videoInformation.Title, Path = videoInformation.Path, Thumbnail = await GetThumbnailPathAsync(videoInformation), Duration = videoInformation.Duration }); } } catch (Exception exception) { Debug.WriteLine(exception.Message); return(itemList); } return(itemList); }
internal static MediaDataReader <MediaInfo> SelectMedia <T>(ForeachFunc <T> func, T param, SelectArguments arguments) { using (var filter = QueryArguments.ToNativeHandle(arguments)) { var items = new List <MediaInfo>(); Exception exception = null; func(param, filter, (mediaInfoHandle, _) => { try { items.Add(MediaInfo.FromHandle(mediaInfoHandle)); return(true); } catch (Exception e) { exception = e; return(false); } }).ThrowIfError("Failed to query"); if (exception != null) { throw exception; } return(new MediaDataReader <MediaInfo>(items)); } }
private static List <PlaylistMember> GetMembers(int playlistId, SelectArguments arguments) { using (var filter = QueryArguments.ToNativeHandle(arguments)) { Exception caught = null; List <PlaylistMember> list = new List <PlaylistMember>(); Interop.Playlist.ForeachMediaFromDb(playlistId, filter, (memberId, mediaInfoHandle, _) => { try { list.Add(new PlaylistMember(memberId, MediaInfo.FromHandle(mediaInfoHandle))); return(true); } catch (Exception e) { caught = e; return(false); } }).ThrowIfError("Failed to query"); if (caught != null) { throw caught; } return(list); } }
/// <summary> /// Gets tracks from device. /// </summary> /// <returns>A collection of audio tracks.</returns> public List <Track> GetTracksFromDevice() { List <Track> tracklist = new List <Track>(); try { _mediaDatabase.Connect(); var selectArgs = new SelectArguments { FilterExpression = "MEDIA_TYPE = " + TYPE_MUSIC }; var mediaInfoCommand = new MediaInfoCommand(_mediaDatabase); var selectedMedia = mediaInfoCommand.SelectMedia(selectArgs); while (selectedMedia.Read()) { tracklist.Add(MediaInfoToTrack((AudioInfo)selectedMedia.Current)); } } catch (Exception e) { Log.Error(SAMPLE_LOG_TAG, e.Message); } finally { _mediaDatabase.Disconnect(); } return(tracklist); }
/// <summary> /// Retrieves the media information under the folder with the <see cref="SelectArguments"/>. /// </summary> /// <param name="folderId">The ID of the folder to select media in the folder.</param> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <MediaInfo> SelectMedia(string folderId, SelectArguments filter) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId)); return(CommandHelper.SelectMedia(Interop.Folder.ForeachMediaFromDb, folderId, filter)); }
public MediaDataReader <MediaInfo> SelectMedia(string storageId, SelectArguments filter) { if (Exists(storageId) == false) { return(new MediaDataReader <MediaInfo>(new MediaInfo[0])); } return(CommandHelper.SelectMedia(Interop.Storage.ForeachMediaFromDb, storageId, filter)); }
public void SelectMedia_WITH_ARGS() { var arguments = new SelectArguments { TotalRowCount = 1 }; var reader = _cmd.SelectMedia(_tagId, arguments); Assert.That(reader.Read(), Is.True); Assert.That(reader.Read(), Is.False); }
/// <summary> /// Retrieves the media information of the playlist with the <see cref="SelectArguments"/>. /// </summary> /// <param name="playlistId">The playlist ID to query with.</param> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <PlaylistMember> SelectMember(int playlistId, SelectArguments filter) { ValidateDatabase(); if (playlistId <= 0) { throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId, "Playlist id can't be less than or equal to zero."); } return(new MediaDataReader <PlaylistMember>(GetMembers(playlistId, filter))); }
/// <summary> /// Retrieves the media information of the album with <see cref="SelectArguments"/>. /// </summary> /// <param name="albumId">The ID of the album to query with.</param> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <MediaInfo> SelectMember(int albumId, SelectArguments filter) { ValidateDatabase(); if (albumId <= 0) { throw new ArgumentOutOfRangeException(nameof(albumId), albumId, "The album id can't be equal to or less than zero."); } return(CommandHelper.SelectMedia(Interop.Album.ForeachMediaFromDb, albumId, filter)); }
/// <summary> /// Retrieves the media information of the tag with the <see cref="SelectArguments"/>. /// </summary> /// <param name="tagId">The tag ID.</param> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="tagId"/> is less than or equal to zero.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <MediaInfo> SelectMedia(int tagId, SelectArguments filter) { ValidateDatabase(); if (tagId <= 0) { throw new ArgumentOutOfRangeException(nameof(tagId), tagId, "Tag id can't be less than or equal to zero."); } return(CommandHelper.SelectMedia(Interop.Tag.ForeachMediaFromDb, tagId, filter)); }
/// <summary> /// Gets files' information. /// </summary> /// <param name="storageIdItems">The collection of storages' IDs which are to be analyzed.</param> /// <param name="type">The type of file's content.</param> /// <returns>A collection of file's information items which meet the terms of filtering.</returns> public IEnumerable <FileInfo> GetFileItems(IEnumerable <string> storageIdItems, Constants.MediaContentType type) { List <FileInfo> fileItems = new List <FileInfo>(); var stringBuilder = new StringBuilder(); stringBuilder.Append("MEDIA_TYPE = "); stringBuilder.Append((int)type); foreach (var storageId in storageIdItems) { var selectArgs = new SelectArguments { FilterExpression = stringBuilder.ToString() + String.Format(DIRECTORY_CONDITION, storageId) }; try { var mediaInfoCommand = new MediaInfoCommand(_mediaDatabase); var selectedMedia = mediaInfoCommand.SelectMedia(selectArgs); while (selectedMedia.Read()) { fileItems.Add(MediaInfoToFileInfo(selectedMedia.Current)); } } catch (Exception e) { if (e is ArgumentNullException || e is InvalidOperationException || e is ObjectDisposedException) { Log.Error(SAMPLE_LOG_TAG, e.Message); } else if (e is MediaDatabaseException) { Log.Warn(SAMPLE_LOG_TAG, String.Format(SELECT_STORAGE_MEDIA_FAIL_MSG, storageId, selectArgs.FilterExpression)); } else { Log.Warn(SAMPLE_LOG_TAG, e.Message); throw; } } } return(fileItems); }
/// <summary> /// Retrieves the tags with the <see cref="SelectArguments"/>. /// </summary> /// <param name="arguments">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <Tag> Select(SelectArguments arguments) { ValidateDatabase(); return(CommandHelper.Select(arguments, Interop.Tag.ForeachTagFromDb, Tag.FromHandle)); }
/// <summary> /// Retrieves the bookmarks with <see cref="SelectArguments"/>. /// </summary> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <Bookmark> Select(SelectArguments filter) { ValidateDatabase(); return(CommandHelper.Select(filter, Interop.Bookmark.ForeachFromDb, Bookmark.FromHandle)); }
/// <summary> /// Retrieves the folders with the <see cref="SelectArguments"/>. /// </summary> /// <param name="arguments">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <Folder> Select(SelectArguments arguments) { ValidateDatabase(); return(CommandHelper.Select(arguments, Interop.Folder.ForeachFolderFromDb, Folder.FromHandle)); }
public MediaDataReader <Storage> Select(SelectArguments arguments) { ValidateDatabase(); return(CommandHelper.Select(arguments, Interop.Storage.ForeachStorageFromDb, Storage.FromHandle)); }
/// <summary> /// Retrieves the albums with <see cref="SelectArguments"/>. /// </summary> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <Album> Select(SelectArguments filter) { ValidateDatabase(); return(CommandHelper.Select(filter, Interop.Album.ForeachAlbumFromDb, Album.FromHandle)); }
/// <summary> /// Retrieves the face information with the <see cref="SelectArguments"/>. /// </summary> /// <param name="filter">The criteria to use to filter. This value can be null.</param> /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns> /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception> /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception> /// <since_tizen> 4 </since_tizen> public MediaDataReader <FaceInfo> Select(SelectArguments filter) { ValidateDatabase(); return(CommandHelper.Select(filter, Interop.Face.ForeachFromDb, FaceInfo.FromHandle)); }