Пример #1
0
        private void OpenPlayList(object obj)
        {
            // playlistLookupDictionary.Clear();
            // playListViewCollection.Clear();
            XmlSerializer  _xmlDeSerializer        = new XmlSerializer(typeof(PlayListDirectory));
            OpenFileDialog _playListOpenFileDialog = new OpenFileDialog();

            _playListOpenFileDialog.Filter = "xml files(*.xml)|*.xml";
            _playListOpenFileDialog.Title  = "Open PlayList";

            if (_playListOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string            filename          = _playListOpenFileDialog.FileName;
                TextReader        _textReader       = new StreamReader(filename);
                object            xmlObject         = _xmlDeSerializer.Deserialize(_textReader);
                PlayListDirectory xmlDataCollection = (PlayListDirectory)xmlObject;
                _textReader.Close();
                foreach (PlayListClass tempList in xmlDataCollection.PlayListCollection)
                {
                    playlistLookupDictionary.Add(tempList.FileName, new Uri(tempList.Filepath, UriKind.Absolute));
                    playListViewCollection.Add(new Uri(tempList.FileName, UriKind.Relative));
                    MediaSource = new Uri(tempList.Filepath, UriKind.Absolute);
                }
            }
        }
Пример #2
0
        private void SavePlaylist(object obj)
        {
            XmlSerializer  _xmlSerializer      = new XmlSerializer(typeof(PlayListDirectory));
            SaveFileDialog _playListSaveDialog = new SaveFileDialog();

            _playListSaveDialog.Filter = "xml files(*.xml)|*.xml";
            _playListSaveDialog.Title  = "Save PlayList";
            if (_playListSaveDialog.ShowDialog() == DialogResult.OK)
            {
                string filename = _playListSaveDialog.FileName;
                using (TextWriter _textWriter = new StreamWriter(filename))
                {
                    PlayListDirectory playListDirectory = new PlayListDirectory();

                    List <PlayListClass> _mediaList = new List <PlayListClass>();
                    foreach (Uri file in PlayListViewCollection)
                    {
                        PlayListClass temp = new PlayListClass();
                        temp.FileName = file.ToString();
                        temp.Filepath = playlistLookupDictionary[file.ToString()].ToString();
                        _mediaList.Add(temp);
                    }
                    playListDirectory.PlayListCollection = _mediaList;
                    _xmlSerializer.Serialize(_textWriter, playListDirectory);
                }
            }
        }