public MediaContentPort()
        {
            mediaDatabase = new MediaDatabase();
            mediaDatabase.Connect();

            mediaInfoCommand = new MediaInfoCommand(mediaDatabase);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        public MediaContentDatabase()
        {
            var database = new MediaDatabase();

            database.Connect();

            _mediaInfoCmd = new MediaInfoCommand(database);
        }
예제 #4
0
        public DataBase()
        {
            var database = new MediaDatabase();

            database.Connect();

            _mediaInfoCmd = new MediaInfoCommand(database);

            _files = Directory.GetFiles(_filePath, "*.jpg").Select(Path.GetFullPath).ToList();
        }
        /// <summary>
        /// This is a sample to demonstrate how to query the media database to retrieve media content
        /// For more information about media content, see https://docs.tizen.org/application/dotnet/guides/multimedia/media-content
        /// </summary>
        public static async Task AccessMediaContentSampleAsync()
        {
            // Ask the user for the permission
            PrivacyPermissionStatus permission = await PrivacyPermissionService.RequestAsync(PrivacyPrivilege.MediaStorage);

            if (permission != PrivacyPermissionStatus.Granted)
            {
                // TODO: The permission is not granted
                return;
            }

            using (var database = new MediaDatabase())
            {
                try
                {
                    // Establish a connection to the media database.
                    database.Connect();

                    // Note that the system automactically scans storage and adds media files to the database.
                    // To request the system to scan a directory explicitly, use MediaDatabase.ScanFolderAsync()
                    // await database.ScanFolderAsync(path);

                    // Query the database to retrieve media files and get a Reader containing results.
                    var command = new MediaInfoCommand(database);
                    var reader  = command.SelectMedia(new SelectArguments()
                    {
                        FilterExpression = $"{MediaInfoColumns.MediaType}={(int)MediaType.Music}"
                                           + $" OR {MediaInfoColumns.MediaType}={(int)MediaType.Sound}"
                                           + $" OR {MediaInfoColumns.MediaType}={(int)MediaType.Video}"
                    });

                    // Iterate over media data in the results.
                    while (reader.Read())
                    {
                        var media = reader.Current;

                        // TODO: Insert code to do something with a media file.
                        // Note that your app needs adequate permissions to perform operations on the file
                        Logger.Info($"{media.MediaType}: {media.Title}");
                    }
                }
                catch (MediaDatabaseException)
                {
                    // TODO: Handle exception as appropriate to your scenario.
                }
            }
        }
        /// <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);
        }
예제 #7
0
        /// <summary>
        /// Get Record from media file
        /// </summary>
        /// <param name="path">recorded audio file</param>
        /// <param name="SttOn">stt on/off mode</param>
        /// <returns>Record</returns>
        public Record GetMediaInfo(string path, bool SttOn)
        {
            Record record = null;

            try
            {
                // TODO : scan
#if media_svc_get_storage_id_failed_return_minus_2
#else
                mediaDB.Connect();
#endif
                mediaDB.ScanFile(path);
#if media_svc_get_storage_id_failed_return_minus_2
#else
                mediaInfoCmd = new MediaInfoCommand(mediaDB);
#endif
                AudioInfo info = mediaInfoCmd.Add(path) as AudioInfo;
#if media_svc_get_storage_id_failed_return_minus_2
#else
                mediaDB.Disconnect();
#endif

                //int minutes = info.Duration / 60000;
                //int seconds = (info.Duration - minutes * 60000) / 1000;
                //string duration = String.Format("{0:00}:{1:00}", minutes, seconds);
                record = new Record
                {
                    _id        = AudioRecordService.numbering,
                    Title      = info.Title.Substring(0, info.Title.IndexOf("_T_")),
                    Date       = info.DateModified.ToLocalTime().ToString("t"),
                    Duration   = info.Duration,
                    Path       = path,
                    SttEnabled = SttOn,
                };
                Console.WriteLine(" ** Record :" + record);
            }
            catch (Exception e)
            {
                Console.WriteLine("###########################################");
                Console.WriteLine("    FAILED GetMediaInfo : " + e.Message + ", " + e.Source);
                Console.WriteLine("###########################################");
                MessagingCenter.Send(this, MessageKeys.ErrorOccur, e);
            }

            return(record);
        }