コード例 #1
0
        /// <summary>
        /// Searches and removes data items of a specific media.
        /// </summary>
        /// <param name="toRemove"></param>
        private void removeFromMediaDataList(NBMedia toRemove)
        {
            IEnumerable <NBMediaDataItem> foundMediaDataItems = mediaDataItems.Where(item => item.Path == toRemove.Path);

            foreach (NBMediaDataItem item in foundMediaDataItems.ToList())
            {
                mediaDataItems.Remove(item);
            }
        }
コード例 #2
0
        /// <summary>
        /// Add the data of a single media.
        /// </summary>
        /// <param name="media"></param>
        private void addToMediaDataList(NBMedia media)
        {
            NBMediaDataItem newItem = new NBMediaDataItem(media);

            if (!mediaDataItems.Contains(newItem))
            {
                mediaDataItems.Add(newItem);
            }
        }
コード例 #3
0
ファイル: NBRegistry.cs プロジェクト: CalebLam14/NebulaPlayer
        /// <summary>
        /// Add a new media data to the registry.
        /// </summary>
        /// <param name="newMedia">The new media data.</param>
        public static async void AddMedia(NBMedia newMedia)
        {
            if (!medias.Where(media => media.Path == newMedia.Path).Any()) // If the registry doesn't have this media data, add it.
            {
                medias.Add(newMedia);
                StorageFile dataFile = await SaveNewMedia(newMedia).ConfigureAwait(true);

                newMedia.DataFile = dataFile;
            }
            else
            {
                await new MessageDialog("This media file has already been added!").ShowAsync(); // Notify the user this has already been added.
            }
        }
コード例 #4
0
ファイル: NBRegistry.cs プロジェクト: CalebLam14/NebulaPlayer
 public static async void DeleteSavedMedia(NBMedia media)
 {
     if (media.DataFile != null)
     {
         try
         {
             await media.DataFile.DeleteAsync();
         }
         catch (Exception ex)
         {
             await new MessageDialog("Can\'t delete " + media.Name + "\'s NBME file: " + ex.Message).ShowAsync();
         }
     }
 }
コード例 #5
0
ファイル: NBRegistry.cs プロジェクト: CalebLam14/NebulaPlayer
        /// <summary>
        /// Returns the genre of the media file based on the media data. The genre is based on what the specific media class it is.
        /// </summary>
        /// <param name="media"></param>
        /// <returns>The media genre.</returns>
        public static MediaType GetMediaType(NBMedia media)
        {
            Type mediaType = media.GetType();

            if (mediaType == typeof(NBAudio))
            {
                return(MediaType.Audio);
            }
            else if (mediaType == typeof(NBVideo))
            {
                return(MediaType.Video);
            }
            else if (mediaType == typeof(NBImage))
            {
                return(MediaType.Image);
            }
            else
            {
                return(MediaType.Unknown); // Return unknown for any other class.
            }
        }
コード例 #6
0
ファイル: NBRegistry.cs プロジェクト: CalebLam14/NebulaPlayer
        /// <summary>
        /// Exports the imported media into a .nbme file and save it in a local folder. It is located in AppData, which is a hidden folder and therefore makes this application really uninteresting on school computers due to their restrictions.
        /// The file is saved like this:
        /// <list type="number">
        ///     <item>Name of the file with extension</item>
        ///     <item>Extension of the file</item>
        ///     <item>Path to the file</item>
        /// </list>
        /// Returns the saved NBME file for reference later.
        /// </summary>
        /// <param name="media">The media object to save.</param>
        public static async Task <StorageFile> SaveNewMedia(NBMedia media)
        {
            StorageFolder dataStorage = ApplicationData.Current.LocalFolder;
            StorageFolder mediasStorageFolder;

            try // Create a save data folder in case it does not exist.
            {
                mediasStorageFolder = await dataStorage.GetFolderAsync(MEDIA_STORAGE_NAME);
            }
            catch (FileNotFoundException)
            {
                mediasStorageFolder = await dataStorage.CreateFolderAsync(MEDIA_STORAGE_NAME);
            }

            string      mediaName         = media.Name;
            string      fileName          = mediaName.Substring(0, mediaName.LastIndexOf('.')) + MEDIA_STORAGE_FORMAT;
            StorageFile targetNBMediaFile = await mediasStorageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); // Create the file or overwrite if it exists already.

            // The data to save.
            // TODO: Save in either hex or binary.
            List <string> contentLines = new List <string>()
            {
                media.Format,
                media.Path,
            };

            try // Try writing the file and notify users if anything bad happens.
            {
                await FileIO.WriteLinesAsync(targetNBMediaFile, contentLines);

                return(targetNBMediaFile);
            }
            catch (Exception ex)
            {
                await new MessageDialog("Can\'t save " + mediaName + ": " + ex.Message).ShowAsync();
                return(null);
            }
        }
コード例 #7
0
 /// <summary>
 /// Supply a plylist source and the data item will set its values based on it.
 /// </summary>
 /// <param name="source">The Media object.</param>
 public NBMediaDataItem(NBMedia source)
     : this(source.Name, source, source.Path, GetMediaType(source))
 {
 }