コード例 #1
0
ファイル: MainForm.cs プロジェクト: modulexcite/HaMusic
        public void LoadSourceState(string path)
        {
            int  pos, vol;
            bool playing;

            lock (DataSource.Lock)
            {
                Playlist library = null;
                if (indexerFinished)
                {
                    library = DataSource.LibraryPlaylist;
                }
                ServerDataSource newSource;
                using (FileStream fs = File.OpenRead(path))
                {
                    Playlist.DeserializeCounters(fs);
                    PlaylistItem.DeserializeCounters(fs);
                    newSource = ServerDataSource.Deserialize(fs);
                }
                lock (newSource.Lock)
                {
                    // Make sure that Current and Next still exist; they might not if the DB was saved when playing from the Library
                    PlaylistItem foo;
                    if (newSource.CurrentItem != null && !newSource.TryGetItem(newSource.CurrentItem.UID, out foo))
                    {
                        newSource.CurrentItem = null;
                    }
                    if (newSource.NextItemOverride != null && !newSource.TryGetItem(newSource.NextItemOverride.UID, out foo))
                    {
                        newSource.NextItemOverride = null;
                    }

                    if (indexerFinished)
                    {
                        newSource.LibraryPlaylist = library;
                    }
                    DataSource = newSource;
                    pos        = DataSource.Position;
                    vol        = DataSource.Volume;
                    playing    = DataSource.Playing;
                    BroadcastMessage(HaProtoImpl.Opcode.SETDB, new HaProtoImpl.SETDB()
                    {
                        dataSource = DataSource
                    });
                }
            }
            mover.OnSetDataSource();
            player.OnSongChanged();
            player.Playing  = playing;
            player.Position = pos;
            player.Volume   = vol;
        }