public void SaveB4s() { PlayList playlist = new PlayList(); IPlayListIO saver = new PlayListB4sIO(); playlist.Add(new PlayListItem("mytuneMp3", "mytune.mp3")); playlist.Add(new PlayListItem("mytuneOgg", "mytune.ogg", 123)); playlist.Add(new PlayListItem("mytuneWav", "mytune.wav")); playlist.Add(new PlayListItem("mytuneWav", "mytune.wav", 666)); saver.Save(playlist, "test.b4s"); string newXml; string oldXml; using (StreamReader reader = new StreamReader("test.b4s")) { newXml = reader.ReadToEnd(); } using (StreamReader reader = new StreamReader("Core\\Playlists\\TestData\\testSave.b4s")) { oldXml = reader.ReadToEnd(); } Assert.AreEqual(oldXml, newXml); }
public static void CompositeExercise() { // Make new empty "Study" playlist PlayList studyPlaylist = new PlayList("Study"); // Make "Synth Pop" playlist and Add 2 songs to it. PlayList synthPopPlaylist = new PlayList("Synth Pop"); Song synthPopSong1 = new Song("Girl Like You", "Toro Y Moi"); Song synthPopSong2 = new Song("Outside", "TOPS"); synthPopPlaylist.Add(synthPopSong1); synthPopPlaylist.Add(synthPopSong2); // Make "Experimental" playlist and Add 3 songs to it, // then set playback speed of the playlist to 0.5x PlayList experimentalPlaylist = new PlayList("Experimental"); Song experimentalSong1 = new Song("About you", "XXYYXX"); Song experimentalSong2 = new Song("Motivation", "Clams Casino"); Song experimentalSong3 = new Song("Computer Vision", "Oneohtrix Point Never"); experimentalPlaylist.Add(experimentalSong1); experimentalPlaylist.Add(experimentalSong2); experimentalPlaylist.Add(experimentalSong3); float slowSpeed = 0.5f; experimentalPlaylist.SetPlaybackSpeed(slowSpeed); // Add the "Synth Pop" playlist to the "Experimental" playlist experimentalPlaylist.Add(synthPopPlaylist); // Add the "Experimental" playlist to the "Study" playlist studyPlaylist.Add(experimentalPlaylist); // Create a new song and set its playback speed to 1.25x, play this song, // get the name of glitchSong → "Textuell", then get the artist of this song → "Oval" Song glitchSong = new Song("Textuell", "Oval"); float fasterSpeed = 1.25f; glitchSong.SetPlaybackSpeed(fasterSpeed); glitchSong.Play(); String name = glitchSong.GetName(); String artist = glitchSong.GetArtist(); Console.WriteLine("The song name is " + name); Console.WriteLine("The song artist is " + artist); // Add glitchSong to the "Study" playlist studyPlaylist.Add(glitchSong); // Play "Study" playlist. studyPlaylist.Play(); // Get the playlist name of studyPlaylist → "Study" Console.WriteLine("The Playlist's name is " + studyPlaylist.GetName()); }
public void AllPlayedReturnsTrueWhenAllArePlayed() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); item.Played = true; pl.Add(item); item = new PlayListItem("my 2:d song", "myfile2.mp3"); item.Played = true; pl.Add(item); Assert.IsTrue(pl.AllPlayed()); }
public void AllPlayedReturnsTrueWhenAllArePlayed() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); item.Played = true; pl.Add(item); item = new PlayListItem("my 2:d song", "myfile2.mp3"); item.Played = true; pl.Add(item); Assert.IsTrue(pl.AllPlayed()); }
/// <summary> /// Adds a list of Music Videos to a playlist, or a list of artists Music Videos /// </summary> /// <param name="items"></param> /// <param name="playNow"></param> /// <param name="clear"></param> private void AddToPlaylist(List <DBTrackInfo> items, bool playNow, bool clear, bool shuffle) { PlayList playlist = Player.playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MVCENTRAL); if (clear) { playlist.Clear(); } foreach (DBTrackInfo video in items) { PlayListItem p1 = new PlayListItem(video); p1.Track = video; p1.FileName = video.LocalMedia[0].File.FullName; playlist.Add(p1); } Player.playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MVCENTRAL; if (shuffle) { playlist.Shuffle(); } if (playNow) { Player.playlistPlayer.Play(0); if (mvCentralCore.Settings.AutoFullscreen) { logger.Debug("Switching to Fullscreen"); GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO); } } }
void RenderPlay(Project project, Play play, MediaFile file) { PlayList playlist; EncodingSettings settings; EditionJob job; string outputDir, outputFile; if (Config.AutoRenderDir == null || !Directory.Exists(Config.AutoRenderDir)) { outputDir = Config.VideosDir; } else { outputDir = Config.AutoRenderDir; } outputFile = String.Format("{0}-{0}.mp4", play.Category.Name, play.Name); outputFile = Path.Combine(outputDir, project.Description.Title, outputFile); try { Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); settings = EncodingSettings.DefaultRenderingSettings(outputFile); playlist = new PlayList(); playlist.Add(new PlayListPlay(play, file, true)); job = new EditionJob(playlist, settings); renderer.AddJob(job); } catch (Exception ex) { Log.Exception(ex); } }
private void SavePlayList() { string strNewFileName = playlistPlayer.CurrentPlaylistName; if (VirtualKeyboard.GetKeyboard(ref strNewFileName, GetID)) { string strPath = Path.GetFileNameWithoutExtension(strNewFileName); string strPlayListPath = string.Empty; using (Profile.Settings xmlreader = new Profile.MPSettings()) { strPlayListPath = xmlreader.GetValueAsString("music", "playlists", string.Empty); strPlayListPath = Util.Utils.RemoveTrailingSlash(strPlayListPath); } strPath += ".m3u"; if (strPlayListPath.Length != 0) { strPath = strPlayListPath + @"\" + strPath; } PlayList playlist = new PlayList(); for (int i = 0; i < facadeLayout.Count; ++i) { GUIListItem pItem = facadeLayout[i]; PlayListItem newItem = new PlayListItem(); newItem.FileName = pItem.Path; newItem.Description = pItem.Label; newItem.Duration = (pItem.MusicTag == null) ? pItem.Duration : (pItem.MusicTag as MusicTag).Duration; newItem.Type = PlayListItem.PlayListItemType.Audio; playlist.Add(newItem); } IPlayListIO saver = new PlayListM3uIO(); saver.Save(playlist, strPath); } }
public bool Load(PlayList playlist, string fileName) { playlist.Clear(); XmlNodeList nodeEntries; if (!LoadXml(fileName, out nodeEntries)) return false; try { string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); foreach (XmlNode node in nodeEntries) { string file = ReadFileName(node); if (file == null) return false; string infoLine = ReadInfoLine(node, file); int duration = ReadLength(node); SetupTv.Utils.GetQualifiedFilename(basePath, ref file); PlayListItem newItem = new PlayListItem(infoLine, file, duration); playlist.Add(newItem); } return true; } catch (Exception) { return false; } }
public override void DeInit() { GUIWindowManager.Receivers -= new SendMessageHandler(this.OnThreadMessage); GUIWindowManager.OnNewAction -= new OnActionHandler(this.OnNewAction); // Save the default Playlist if (_savePlaylistOnExit) { Log.Info("Playlist: Saving default playlist {0}", _defaultPlaylist); IPlayListIO saver = new PlayListM3uIO(); PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayList playlistTmp = new PlayList(); // Sort out Playlist Items residing on a CD, as they are gonna most likely to change foreach (PlayListItem item in playlist) { if (Path.GetExtension(item.FileName) != ".cda") { playlistTmp.Add(item); } } if (playlistTmp.Count > 0) { saver.Save(playlistTmp, Path.Combine(_playlistFolder, _defaultPlaylist)); } } base.DeInit(); }
public void ResetSetsAllItemsToFalse() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); pl.Add(item); PlayListItem item2 = new PlayListItem("my 2:d song", "myfile2.mp3"); pl.Add(item2); pl[0].Played = true; pl[1].Played = true; pl.ResetStatus(); Assert.IsFalse(pl[0].Played); Assert.IsFalse(pl[1].Played); }
public PlayListViewModel(IList <PlayListEntryViewModel> list, string title) : base(title) { foreach (var entry in list) { PlayList.Add(entry.RegisterOwner(this)); } Initialize(); }
public void NewlyAddedSongsAreNotMarkedPlayed() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); pl.Add(item); Assert.IsFalse(pl.AllPlayed()); }
public List <EditionJob> ConfigureRenderingJob(IPlayList playlist) { VideoEditionProperties vep; List <EditionJob> jobs = new List <EditionJob>(); int response; if (playlist.Count == 0) { WarningMessage(Catalog.GetString("The playlist you want to render is empty.")); return(null); } vep = new VideoEditionProperties(); vep.TransientFor = mainWindow as Gtk.Window; response = vep.Run(); while (response == (int)ResponseType.Ok) { if (!vep.SplitFiles && vep.EncodingSettings.OutputFile == "") { WarningMessage(Catalog.GetString("Please, select a video file.")); response = vep.Run(); } else if (vep.SplitFiles && vep.OutputDir == "") { WarningMessage(Catalog.GetString("Please, select an output directory.")); response = vep.Run(); } else { break; } } if (response == (int)ResponseType.Ok) { if (!vep.SplitFiles) { jobs.Add(new EditionJob(playlist, vep.EncodingSettings)); } else { int i = 0; foreach (PlayListPlay play in playlist) { EncodingSettings settings = vep.EncodingSettings; PlayList pl = new PlayList(); string filename = String.Format("{0}-{1}.{2}", i.ToString("d4"), play.Name, settings.EncodingProfile.Extension); pl.Add(play); settings.OutputFile = Path.Combine(vep.OutputDir, filename); jobs.Add(new EditionJob(pl, settings)); i++; } } } vep.Destroy(); return(jobs); }
/// <summary> /// Play tracks by selected Genre /// </summary> private void playByGenre() { GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlgMenu != null) { dlgMenu.Reset(); dlgMenu.SetHeading(mvCentralUtils.PluginName() + " - " + Localization.SmartPlaylistOptions); List <DBGenres> genreList = DBGenres.GetAll(); genreList.Sort(delegate(DBGenres p1, DBGenres p2) { return(p1.Genre.CompareTo(p2.Genre)); }); foreach (DBGenres genre in genreList) { if (genre.Enabled) { dlgMenu.Add(genre.Genre); } } dlgMenu.DoModal(GetID); if (dlgMenu.SelectedLabel == -1) // Nothing was selected { return; } //dlgMenu.SelectedLabelText PlayList playlist = Player.playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MVCENTRAL); playlist.Clear(); List <DBArtistInfo> allArtists = DBArtistInfo.GetAll(); foreach (DBArtistInfo artist in allArtists) { if (tagMatched(dlgMenu.SelectedLabelText, artist)) { logger.Debug("Matched Artist {0} with Tag {1}", artist.Artist, dlgMenu.SelectedLabelText); List <DBTrackInfo> theTracks = DBTrackInfo.GetEntriesByArtist(artist); foreach (DBTrackInfo artistTrack in theTracks) { playlist.Add(new PlayListItem(artistTrack)); } } } Player.playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MVCENTRAL; if (mvCentralCore.Settings.GeneratedPlaylistAutoShuffle) { playlist.Shuffle(); } Player.playlistPlayer.Play(0); if (mvCentralCore.Settings.AutoFullscreen) { GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO); } } }
public void NewlyAddedSongsAreNotMarkedPlayed() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); pl.Add(item); Assert.IsFalse(pl.AllPlayed()); }
public PlayListViewModel(string title, IEnumerable <NicoNicoSearchResultEntry> entries) : base("プレイリスト\n" + title) { foreach (var entry in entries) { PlayList.Add(new PlayListEntryViewModel(entry)); } SelectedPlayList = PlayList.First(); }
public bool Load(PlayList playlist, string fileName) { playlist.Clear(); try { var basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); var doc = new XmlDocument(); doc.Load(fileName); if (doc.DocumentElement == null) { return(false); } var nodeRoot = doc.DocumentElement.SelectSingleNode("/asx"); if (nodeRoot == null) { return(false); } var nodeEntries = nodeRoot.SelectNodes("entry"); foreach (XmlNode node in nodeEntries) { var srcNode = node.SelectSingleNode("ref"); if (srcNode != null) { var url = srcNode.Attributes.GetNamedItem("href"); if (url != null) { if (url.InnerText != null) { if (url.InnerText.Length > 0) { fileName = url.InnerText; if ( !(fileName.ToLowerInvariant().StartsWith("http") || fileName.ToLowerInvariant().StartsWith("mms") || fileName.ToLowerInvariant().StartsWith("rtp"))) { continue; } var newItem = new PlayListItem(fileName, fileName, 0); newItem.Type = PlayListItem.PlayListItemType.Audio; playlist.Add(newItem); } } } } } return(true); } catch (Exception ex) { Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace); } return(false); }
void HandleRender(object sender, EventArgs e) { if (RenderPlaylist != null) { PlayList pl = new PlayList(); pl.Add(new PlayListPlay(menuToNodeDict[sender as MenuItem], mediaFile, true)); RenderPlaylist(pl); } }
public void ResetSetsAllItemsToFalse() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); pl.Add(item); PlayListItem item2 = new PlayListItem("my 2:d song", "myfile2.mp3"); pl.Add(item2); pl[0].Played = true; pl[1].Played = true; pl.ResetStatus(); Assert.IsFalse(pl[0].Played); Assert.IsFalse(pl[1].Played); }
public void RemoveReallyRemovesASong() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); pl.Add(item); pl.Remove("myfile.mp3"); Assert.AreEqual(0, pl.Count); }
public int PlaylistHandler(NameValueCollection parameters) { Uri uri = new Uri("http://www.amclassical.com/piano/"); var data = new HttpClient() .GetAsync(uri) .Result.Content .ReadAsStringAsync() .Result; PlayList pl = new PlayList(PlayListType.Music); List <ListItem> items = new List <ListItem> { }; var matches = new Regex("<a href=\"?(.*?)\"?>.*</a>").Matches(data); var number = Math.Min(5, matches.Count); for (var i = 0; i < number; i++) { string path = matches[i].Groups[1].Value.ToLower(); if (!path.EndsWith("mp3")) { continue; } string url = uri.GetLeftPart(UriPartial.Authority) + path; pl.Add(url); items.Add(new ListItem(label: Path.GetFileName(path), url: url)); } List.Add(items); List.Show(); var player = new XbmcPlayer(); player.Play(pl); for (int i = 0; i < pl.Count; i++) { while (!player.IsPlayingAudio) { Kodi.Sleep(TimeSpan.FromMilliseconds(200)); } var info = player.MusicInfoTag; Console.WriteLine($"[NOW PLAYING]: {player.PlayingFile}"); Console.WriteLine("====================="); Console.WriteLine($"{info.URL}, {info.Title}"); Kodi.Sleep(TimeSpan.FromSeconds(5)); player.PlayNext(); } return(0); }
public void GetNextReturnsFileName() { PlayListPlayer player = new PlayListPlayer(); player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; PlayList playlist = player.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListItem item1 = new PlayListItem("apa", "c:\\apa.mp3"); playlist.Add(item1); Assert.AreEqual("c:\\apa.mp3", player.GetNext()); }
public void RemoveReallyRemovesASong() { PlayList pl = new PlayList(); PlayListItem item = new PlayListItem("my song", "myfile.mp3"); pl.Add(item); pl.Remove("myfile.mp3"); Assert.AreEqual(0, pl.Count); }
public void NextTest1() { var _target = new PlayList(); _target.Add("file1.mid"); _target.Add("file2.mid"); _target.Add("file3.mid"); AreEqual("file1.mid", _target.Next); AreEqual("file2.mid", _target.Next); AreEqual("file3.mid", _target.Next); AreEqual("file1.mid", _target.Next); AreEqual("file2.mid", _target.Next); _target.Add("file4.mid"); AreEqual("file3.mid", _target.Next); AreEqual("file4.mid", _target.Next); AreEqual("file1.mid", _target.Next); AreEqual("file2.mid", _target.Next); AreEqual("file3.mid", _target.Next); AreEqual("file4.mid", _target.Next); }
public void InsertItemButNotStartPlayingGivesNull() { PlayListPlayer player = new PlayListPlayer(); player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; PlayList playlist = player.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListItem item1 = new PlayListItem(); playlist.Add(item1); Assert.IsNull(player.GetCurrentItem()); }
public PlayListViewModel(IList <MylistListEntryViewModel> list, string title) : base(title) { foreach (var entry in list) { //ブロマガとかプレイリストに突っ込まれても困るので弾く if (entry.Entry.Type == 0) { PlayList.Add(new PlayListEntryViewModel(entry).RegisterOwner(this)); } } Initialize(); }
private void PlaylistAddUrl() { View?.SetPage(TabPage.PlayList); var urld = new AddURLDialog(); urld.OkClicked = new Action(() => { if (!string.IsNullOrEmpty(urld.Url)) { PlayList.Add(urld.Url); } }); }
public bool Load(PlayList playlist, string fileName) { playlist.Clear(); try { string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); XmlDocument doc = new XmlDocument(); doc.Load(fileName); if (doc.DocumentElement == null) { return false; } XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/asx"); if (nodeRoot == null) { return false; } XmlNodeList nodeEntries = nodeRoot.SelectNodes("entry"); foreach (XmlNode node in nodeEntries) { XmlNode srcNode = node.SelectSingleNode("ref"); if (srcNode != null) { XmlNode url = srcNode.Attributes.GetNamedItem("href"); if (url != null) { if (url.InnerText != null) { if (url.InnerText.Length > 0) { fileName = url.InnerText; if (!(fileName.ToLowerInvariant().StartsWith("http") || fileName.ToLowerInvariant().StartsWith("mms") || fileName.ToLowerInvariant().StartsWith("rtp"))) continue; PlayListItem newItem = new PlayListItem(fileName, fileName, 0); newItem.Type = PlayListItem.PlayListItemType.Audio; playlist.Add(newItem); } } } } } return true; } catch (Exception ex) { Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace); } return false; }
public async void DoLoad(IEnumerable <string> items) { View?.SetPage(TabPage.PlayList); if (items == null) { items = Environment.GetCommandLineArgs(); } foreach (var item in items) { var ext = Path.GetExtension(item).ToLower(); if (!string.IsNullOrEmpty(ext) && App.Playlists.Contains(ext)) { string[] result = null; switch (ext) { case ".pls": result = await PlaylistLoaders.LoadPls(item); break; case ".m3u": result = await PlaylistLoaders.LoadM3u(item); break; case ".wpl": result = await PlaylistLoaders.LoadWPL(item); break; case ".asx": result = await PlaylistLoaders.LoadASX(item); break; } PlayList.AddRange(result); } else if (App.Formats.Contains(ext)) { PlayList.Add(item); } else { MessageBox.Show(Properties.Resources.Playlist_UnsupportedListFormat, Properties.Resources.Playlist_UnsupportedListFormatTitle, MessageBoxButton.OK, MessageBoxImage.Error); } } }
public void PlayMovesCurrentToItem() { PlayListPlayer player = new PlayListPlayer(); player.g_Player = this; //fake g_Player player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; PlayList playlist = player.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListItem item1 = new PlayListItem(); playlist.Add(item1); player.PlayNext(); Assert.AreEqual(item1, player.GetCurrentItem()); Assert.IsTrue(hasPlayBeenCalled); }
public void SaveB4s() { PlayList playlist = new PlayList(); IPlayListIO saver = new PlayListB4sIO(); playlist.Add(new PlayListItem("mytuneMp3", "mytune.mp3")); playlist.Add(new PlayListItem("mytuneOgg", "mytune.ogg", 123)); playlist.Add(new PlayListItem("mytuneWav", "mytune.wav")); playlist.Add(new PlayListItem("mytuneWav", "mytune.wav", 666)); saver.Save(playlist, "test.b4s"); string newXml; string oldXml; using (StreamReader reader = new StreamReader("test.b4s")) { newXml = reader.ReadToEnd(); } using (StreamReader reader = new StreamReader("Core\\Playlists\\TestData\\testSave.b4s")) { oldXml = reader.ReadToEnd(); } Assert.AreEqual(oldXml, newXml); }
public bool SavePlaylist(string playlistId, IEnumerable <WebPlaylistItem> playlistItems) { String path = GetPlaylistPath(playlistId); PlayList mpPlaylist = new PlayList(); IPlayListIO factory = PlayListFactory.CreateIO(path); foreach (WebPlaylistItem i in playlistItems) { PlayListItem mpItem = new PlayListItem(i.Title, i.Path[0], i.Duration); mpItem.Type = PlayListItem.PlayListItemType.Audio; mpPlaylist.Add(mpItem); } return(factory.Save(mpPlaylist, path)); }
public bool Load(PlayList playlist, string fileName) { playlist.Clear(); try { string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); XmlDocument doc = new XmlDocument(); doc.Load(fileName); if (doc.DocumentElement == null) { return false; } XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/smil/body/seq"); if (nodeRoot == null) { return false; } XmlNodeList nodeEntries = nodeRoot.SelectNodes("media"); foreach (XmlNode node in nodeEntries) { XmlNode srcNode = node.Attributes.GetNamedItem("src"); if (srcNode != null) { if (srcNode.InnerText != null) { if (srcNode.InnerText.Length > 0) { fileName = srcNode.InnerText; Util.Utils.GetQualifiedFilename(basePath, ref fileName); PlayListItem newItem = new PlayListItem(fileName, fileName, 0); newItem.Type = PlayListItem.PlayListItemType.Audio; string description; description = Path.GetFileName(fileName); newItem.Description = description; playlist.Add(newItem); } } } } return true; } catch (Exception ex) { Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace); } return false; }
/// <summary> /// Opens m3u8 file and loads the play list collection with the included songs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenM3u8File_Button_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Plex Export|*.m3u8"; openFileDialog1.Title = "Select a Playlist Export"; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SelectedM3u8File = openFileDialog1.FileName; string line; using (Stream stream = openFileDialog1.OpenFile()) { using (StreamReader sr = new StreamReader(stream)) { if (cbxDeleteOnLoad.Checked) { PlayList.ClearItems(); } line = sr.ReadLine(); while (line != null) { if (line.StartsWith("#{\"Id\":")) { List <string> m3u8SongExportList = new List <string>(); m3u8SongExportList.Add(line); m3u8SongExportList.Add(sr.ReadLine()); m3u8SongExportList.Add(sr.ReadLine()); PlayListSong thisSong = new PlayListSong(m3u8SongExportList); PlayList.Add(thisSong); //DownloadOutput.AppendText(Environment.NewLine + thisSong.Path); //if (DownloadOutput.Lines.Count() != 0) // DownloadOutput.Text += Environment.NewLine; //DownloadOutput.Text += thisSong.Title + thisSong.Extension; } line = sr.ReadLine(); } } }; } }
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { switch (requestCode) { case (int)Request.SoundFont: soundFontPath = getActualPathBy(data); if (!(soundFontPath.Contains(".SF2") || soundFontPath.Contains(".sf2"))) { Log.Warn("not a sound font."); break; } Log.Info($"selected: {soundFontPath}"); Synth.SoundFontPath = soundFontPath; Env.SoundFontDir = soundFontPath.ToDirectoryName(); Title = $"MidiPlayer: {midiFilePath.ToFileName()} {soundFontPath.ToFileName()}"; break; case (int)Request.MidiFile: midiFilePath = getActualPathBy(data); if (!(midiFilePath.Contains(".MID") || midiFilePath.Contains(".mid"))) { Log.Warn("not a midi file."); break; } Log.Info($"selected: {midiFilePath}"); Synth.MidiFilePath = midiFilePath; Env.MidiFileDir = midiFilePath.ToDirectoryName(); Title = $"MidiPlayer: {midiFilePath.ToFileName()} {soundFontPath.ToFileName()}"; break; case (int)Request.AddPlayList: var _midiFilePath = getActualPathBy(data); if (!(_midiFilePath.Contains(".MID") || _midiFilePath.Contains(".mid"))) { Log.Warn("not a midi file."); break; } Log.Info($"selected: {_midiFilePath}"); playList.Add(_midiFilePath); // add to playlist Env.MidiFileDir = _midiFilePath.ToDirectoryName(); break; default: break; } }
static void Main(string[] args) { MediaLibrary library = new MediaLibrary(); IPlayList <Video> videoPlayList = new PlayList(); IPlayList <Image> imagePlayList = new PlayList(); IPlayList <Audio> audioPlayList = new PlayList(); videoPlayList.Add(new Video()); imagePlayList.Add(new Image()); audioPlayList.Add(new Audio()); library.AddPlayList((PlayList)audioPlayList); library.AddPlayList((PlayList)videoPlayList); library.AddPlayList((PlayList)imagePlayList); library.PlayAllPlayLists(); Console.ReadKey(); }
public void AddItemToPlayList(GUIListItem pItem, ref PlayList playList, VideoInfo qa) { if (playList == null || pItem == null) { return; } string PlayblackUrl = ""; YouTubeEntry vid; LocalFileStruct file = pItem.MusicTag as LocalFileStruct; if (file != null) { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId); Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl); vid = video.YouTubeEntry; } else { vid = pItem.MusicTag as YouTubeEntry; } if (vid != null) { if (vid.Media.Contents.Count > 0) { PlayblackUrl = string.Format("http://www.youtube.com/v/{0}", Youtube2MP.getIDSimple(vid.Id.AbsoluteUri)); } else { PlayblackUrl = vid.AlternateUri.ToString(); } PlayListItem playlistItem = new PlayListItem(); playlistItem.Type = PlayListItem.PlayListItemType.VideoStream;// Playlists.PlayListItem.PlayListItemType.Audio; qa.Entry = vid; playlistItem.FileName = PlayblackUrl; playlistItem.Description = pItem.Label; playlistItem.Duration = pItem.Duration; playlistItem.MusicTag = qa; playList.Add(playlistItem); } }
public bool Load(PlayList playlist, string playlistFileName) { playlist.Clear(); try { var doc = new XmlDocument(); doc.Load(playlistFileName); if (doc.DocumentElement == null) return false; XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/smil/body/seq"); if (nodeRoot == null) return false; XmlNodeList nodeEntries = nodeRoot.SelectNodes("media"); if (nodeEntries != null) foreach (XmlNode node in nodeEntries) { XmlNode srcNode = node.Attributes.GetNamedItem("src"); if (srcNode != null) { if (srcNode.InnerText != null) { if (srcNode.InnerText.Length > 0) { var playlistUrl = srcNode.InnerText; var newItem = new PlayListItem(playlistUrl, playlistUrl, 0) { Type = PlayListItem.PlayListItemType.Audio }; string description = Path.GetFileName(playlistUrl); newItem.Description = description; playlist.Add(newItem); } } } } return true; } catch (Exception e) { Log.Error(e.StackTrace); } return false; }
/// <summary> /// Create a Random Playlist of All Videos /// </summary> private void playRandomAll() { PlayList playlist = Player.playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MVCENTRAL); playlist.Clear(); List <DBTrackInfo> videos = DBTrackInfo.GetAll(); foreach (DBTrackInfo video in videos) { playlist.Add(new PlayListItem(video)); } Player.playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MVCENTRAL; playlist.Shuffle(); Player.playlistPlayer.Play(0); if (mvCentralCore.Settings.AutoFullscreen) { GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO); } }
public bool Load(PlayList playlist, string fileName) { playlist.Clear(); XmlNodeList nodeEntries; if (!LoadXml(fileName, out nodeEntries)) { return false; } try { string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); foreach (XmlNode node in nodeEntries) { string file = ReadFileName(node); if (file == null) { return false; } string infoLine = ReadInfoLine(node, file); int duration = ReadLength(node); file = PathUtil.GetAbsolutePath(basePath, file); PlayListItem newItem = new PlayListItem(infoLine, file, duration); playlist.Add(newItem); } return true; } catch (Exception ex) { Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace); return false; } }
private void Play_Step2(PlayListItem playItem, List<String> urlList, bool goFullScreen) { RemoveInvalidUrls(urlList); // if no valid urls were returned show error msg if (urlList == null || urlList.Count == 0) { notification.Show(Translation.Instance.Error, Translation.Instance.UnableToPlayVideo); return; } // create playlist entries if more than one url if (urlList.Count > 1) { PlayList playbackItems = new PlayList(); foreach (string url in urlList) { VideoInfo vi = playItem.Video.CloneForPlaylist(url, url == urlList[0]); string url_new = url; if (url == urlList[0]) { url_new = SelectedSite.GetPlaylistItemVideoUrl(vi, string.Empty, CurrentPlayList != null && CurrentPlayList.IsPlayAll); } playbackItems.Add(new PlayListItem(vi, playItem.Util) { FileName = url_new }); } if (CurrentPlayList == null) { CurrentPlayList = playbackItems; } else { int currentPlaylistIndex = CurrentPlayListItem != null ? CurrentPlayList.IndexOf(CurrentPlayListItem) : 0; CurrentPlayList.InsertRange(currentPlaylistIndex, playbackItems); } // make the first item the current to be played now playItem = playbackItems[0]; urlList = new List<string>(new string[] { playItem.FileName }); } // play the first or only item string urlToPlay = urlList[0]; if (playItem.Video.PlaybackOptions != null && playItem.Video.PlaybackOptions.Count > 0) { string choice = null; if (playItem.Video.PlaybackOptions.Count > 1) { PlaybackChoices dlg = new PlaybackChoices(); dlg.Owner = this; dlg.lvChoices.ItemsSource = playItem.Video.PlaybackOptions.Keys; var preSelectedItem = playItem.Video.PlaybackOptions.FirstOrDefault(kvp => kvp.Value == urlToPlay); if (!string.IsNullOrEmpty(preSelectedItem.Key)) dlg.lvChoices.SelectedValue = preSelectedItem.Key; if (dlg.lvChoices.SelectedIndex < 0) dlg.lvChoices.SelectedIndex = 0; if (dlg.ShowDialog() == true) choice = dlg.lvChoices.SelectedItem.ToString(); } else { choice = playItem.Video.PlaybackOptions.Keys.First(); } if (choice != null) { playItem.ChosenPlaybackOption = choice; Log.Info("Chosen quality: '{0}'", choice); waitCursor.Visibility = System.Windows.Visibility.Visible; Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback(delegate() { return playItem.Video.GetPlaybackOptionUrl(choice); }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, Translation.Instance.GettingPlaybackUrlsForVideo)) { Play_Step3(playItem, resultInfo.ResultObject as string, goFullScreen); } }, true); } } else { Play_Step3(playItem, urlToPlay, goFullScreen); } }
private void AddToPlayList(PlayList tmpPlayList, IEnumerable<object> sortedPlayList) { foreach (string file in sortedPlayList) { // Remove stop data if exists int idFile = VideoDatabase.GetFileId(file); if (idFile >= 0) { VideoDatabase.DeleteMovieStopTime(idFile); } // Add file to tmp playlist PlayListItem newItem = new PlayListItem(); newItem.FileName = file; // Set file description (for sorting by name -> DVD IFO file problem) string description = string.Empty; if (file.ToUpperInvariant().IndexOf(@"\VIDEO_TS\VIDEO_TS.IFO", StringComparison.InvariantCultureIgnoreCase) >= 0) { string dvdFolder = file.Substring(0, file.ToUpperInvariant().IndexOf(@"\VIDEO_TS\VIDEO_TS.IFO", StringComparison.InvariantCultureIgnoreCase)); description = Path.GetFileName(dvdFolder); } if (file.ToUpperInvariant().IndexOf(@"\BDMV\INDEX.BDMV", StringComparison.InvariantCultureIgnoreCase) >= 0) { string bdFolder = file.Substring(0, file.ToUpperInvariant().IndexOf(@"\BDMV\INDEX.BDMV", StringComparison.InvariantCultureIgnoreCase)); description = Path.GetFileName(bdFolder); } else { description = Path.GetFileName(file); } newItem.Description = description; newItem.Type = PlayListItem.PlayListItemType.Video; tmpPlayList.Add(newItem); } }
public override void DeInit() { GUIWindowManager.Receivers -= new SendMessageHandler(this.OnThreadMessage); GUIWindowManager.OnNewAction -= new OnActionHandler(this.OnNewAction); if (_lastRequest != null) { ascrobbler.RemoveRequest(_lastRequest); } // Save the default Playlist if (_savePlaylistOnExit) { Log.Info("Playlist: Saving default playlist {0}", _defaultPlaylist); IPlayListIO saver = new PlayListM3uIO(); PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayList playlistTmp = new PlayList(); // Sort out Playlist Items residing on a CD, as they are gonna most likely to change foreach (PlayListItem item in playlist) { if (Path.GetExtension(item.FileName) != ".cda") { playlistTmp.Add(item); } } if (playlistTmp.Count > 0) { saver.Save(playlistTmp, Path.Combine(_playlistFolder, _defaultPlaylist)); } } base.DeInit(); }
private void SavePlayList() { string strNewFileName = playlistPlayer.CurrentPlaylistName; if (GetKeyboard(ref strNewFileName)) { string strPath = Path.GetFileNameWithoutExtension(strNewFileName); string strPlayListPath = string.Empty; using (Profile.Settings xmlreader = new Profile.MPSettings()) { strPlayListPath = xmlreader.GetValueAsString("music", "playlists", string.Empty); strPlayListPath = Util.Utils.RemoveTrailingSlash(strPlayListPath); } strPath += ".m3u"; if (strPlayListPath.Length != 0) { strPath = strPlayListPath + @"\" + strPath; } PlayList playlist = new PlayList(); for (int i = 0; i < facadeLayout.Count; ++i) { GUIListItem pItem = facadeLayout[i]; PlayListItem newItem = new PlayListItem(); newItem.FileName = pItem.Path; newItem.Description = pItem.Label; newItem.Duration = pItem.Duration; newItem.Type = PlayListItem.PlayListItemType.Audio; playlist.Add(newItem); } IPlayListIO saver = new PlayListM3uIO(); saver.Save(playlist, strPath); } }
private void OnSavePlayList() { currentSelectedItem = facadeLayout.SelectedListItemIndex; string playlistFileName = string.Empty; if (GetKeyboard(ref playlistFileName)) { string playListPath = string.Empty; using (Profile.Settings xmlreader = new Profile.MPSettings()) { playListPath = xmlreader.GetValueAsString("movies", "playlists", string.Empty); playListPath = Util.Utils.RemoveTrailingSlash(playListPath); } string fullPlayListPath = Path.GetFileNameWithoutExtension(playlistFileName); fullPlayListPath += ".m3u"; if (playListPath.Length != 0) { fullPlayListPath = playListPath + @"\" + fullPlayListPath; } PlayList playlist = new PlayList(); for (int i = 0; i < facadeLayout.Count; ++i) { GUIListItem listItem = facadeLayout[i]; PlayListItem playListItem = new PlayListItem(); playListItem.FileName = listItem.Path; playListItem.Description = listItem.Label; playListItem.Duration = listItem.Duration; playListItem.Type = PlayListItem.PlayListItemType.Video; playlist.Add(playListItem); } PlayListM3uIO saver = new PlayListM3uIO(); saver.Save(playlist, fullPlayListPath); } }
public void AddItemToPlayList(YouTubeEntry vid, ref PlayList playList, VideoInfo qa) { if (playList == null || vid == null) return; string PlayblackUrl = ""; List<GUIListItem> list = new List<GUIListItem>(); if (vid != null) { if (vid.Media.Contents.Count > 0) { PlayblackUrl = string.Format("http://www.youtube.com/v/{0}", Youtube2MP.getIDSimple(vid.Id.AbsoluteUri)); } else { PlayblackUrl = vid.AlternateUri.ToString(); } PlayListItem playlistItem = new PlayListItem(); playlistItem.Type = PlayListItem.PlayListItemType.VideoStream;// Playlists.PlayListItem.PlayListItemType.Audio; qa.Entry = vid; playlistItem.FileName = PlayblackUrl; playlistItem.Description = vid.Title.Text; try { playlistItem.Duration = Convert.ToInt32(vid.Duration.Seconds, 10); } catch { } playlistItem.MusicTag = qa; playList.Add(playlistItem); } }
private void OnSavePlayList() { currentSelectedItem = m_Facade.SelectedListItemIndex; string playlistFileName = string.Empty; if (GetKeyboard(ref playlistFileName)) { string playListPath = string.Empty; playListPath = DBOption.GetOptions(DBOption.cPlaylistPath); playListPath = MediaPortal.Util.Utils.RemoveTrailingSlash(playListPath); // check if Playlist folder exists, create it if not if (!Directory.Exists(playListPath)){ try { Directory.CreateDirectory(playListPath); } catch (Exception e){ MPTVSeriesLog.Write("Error: Unable to create Playlist path: " + e.Message); return; } } string fullPlayListPath = Path.GetFileNameWithoutExtension(playlistFileName); fullPlayListPath += ".tvsplaylist"; if (playListPath.Length != 0) { fullPlayListPath = playListPath + @"\" + fullPlayListPath; } PlayList playlist = new PlayList(); for (int i = 0; i < m_Facade.Count; ++i) { GUIListItem listItem = m_Facade[i]; PlayListItem playListItem = new PlayListItem(); playListItem.Episode = listItem.TVTag as DBEpisode; playlist.Add(playListItem); } PlayListIO saver = new PlayListIO(); saver.Save(playlist, fullPlayListPath); } }
private PlayList parsePlaylist(string contentToParse, PlayListType type) { string regex = null; switch (type) { case PlayListType.m3u: regex = @"(#|.*?#)EXTINF:.*?,(?<name>.*?)(?<playlink>http.*?mp3)"; break; case PlayListType.xspf: regex = "<location>(?<playlink>http[^>]*)</location>.*?(<annotation>|<title>)(?<name>[^>]*)(</annotation>|</title>)"; break; case PlayListType.pls: regex = "File.*?=(?<playlink>.*?mp3).*?Title.*?=(?<name>.*?)Length"; break; case PlayListType.asx: regex = "<entry>.*?<title>(?<name>.*?)</title>[^>]*<Ref href=\"(?<playlink>.*?)\"/>"; break; } PlayList _playlist = new PlayList(); MatchCollection allMatchResults = null; try { Regex regexObj = new Regex(regex, RegexOptions.Singleline | RegexOptions.IgnoreCase); allMatchResults = regexObj.Matches(contentToParse); if (allMatchResults.Count > 0) { for (int i = 0; i < allMatchResults.Count; i++) { Match m = allMatchResults[i]; string name = m.Groups["name"].ToString(); string link = m.Groups["playlink"].ToString(); if (link.Contains("&")) { link = link.Replace("&", "&"); } if (link.Contains("\r")) { link = link.Replace("\r", ""); } PlayListItem item = new PlayListItem(name, link); item.Type = PlayListItem.PlayListItemType.AudioStream; _playlist.Add(item); } } } catch (ArgumentException ex) { throw ex; } return _playlist; }
/// <summary> /// Save player state (when form was resized) /// </summary> protected void SavePlayerState() { if (!_wasPlayingVideo && (g_Player.Playing && (g_Player.IsTV || g_Player.IsVideo || g_Player.IsDVD))) { _wasPlayingVideo = true; // Some Audio/video is playing _currentPlayerPos = g_Player.CurrentPosition; _currentPlayListType = PlaylistPlayer.CurrentPlaylistType; _currentPlayList = new PlayList(); Log.Info("D3D: Saving fullscreen state for resume: {0}", Menu == null); var tempList = PlaylistPlayer.GetPlaylist(_currentPlayListType); if (tempList.Count == 0 && g_Player.IsDVD) { // DVD is playing var itemDVD = new PlayListItem {FileName = g_Player.CurrentFile, Played = true, Type = PlayListItem.PlayListItemType.DVD}; tempList.Add(itemDVD); } foreach (var itemNew in tempList) { _currentPlayList.Add(itemNew); } _currentFile = PlaylistPlayer.Get(PlaylistPlayer.CurrentSong); if (_currentFile.Equals(string.Empty) && g_Player.IsDVD) { _currentFile = g_Player.CurrentFile; } Log.Info("D3D: Stopping media - Current playlist: Type: {0} / Size: {1} / Current item: {2} / Filename: {3} / Position: {4}", _currentPlayListType, _currentPlayList.Count, PlaylistPlayer.CurrentSong, _currentFile, _currentPlayerPos); g_Player.Stop(); _lastActiveWindow = GUIWindowManager.ActiveWindow; } }
public bool Load(PlayList playlist, string fileName) { string extension = Path.GetExtension(fileName); extension.ToLowerInvariant(); playlist.Clear(); playlist.Name = Path.GetFileName(fileName); string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); Encoding fileEncoding = Encoding.Default; FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader file = new StreamReader(stream, fileEncoding, true); string line = file.ReadLine(); if (line == null) { file.Close(); return false; } string strLine = line.Trim(); //CUtil::RemoveCRLF(strLine); if (strLine != START_PLAYLIST_MARKER) { if (strLine.StartsWith("http") || strLine.StartsWith("HTTP") || strLine.StartsWith("mms") || strLine.StartsWith("MMS") || strLine.StartsWith("rtp") || strLine.StartsWith("RTP")) { PlayListItem newItem = new PlayListItem(strLine, strLine, 0); newItem.Type = PlayListItem.PlayListItemType.AudioStream; playlist.Add(newItem); file.Close(); return true; } fileEncoding = Encoding.Default; // No unicode??? rtv stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); file = new StreamReader(stream, fileEncoding, true); //file.Close(); //return false; } string infoLine = ""; string durationLine = ""; fileName = ""; line = file.ReadLine(); while (line != null) { strLine = line.Trim(); //CUtil::RemoveCRLF(strLine); int equalPos = strLine.IndexOf("="); if (equalPos > 0) { string leftPart = strLine.Substring(0, equalPos); equalPos++; string valuePart = strLine.Substring(equalPos); leftPart = leftPart.ToLowerInvariant(); if (leftPart.StartsWith("file")) { if (valuePart.Length > 0 && valuePart[0] == '#') { line = file.ReadLine(); continue; } if (fileName.Length != 0) { PlayListItem newItem = new PlayListItem(infoLine, fileName, 0); playlist.Add(newItem); infoLine = ""; durationLine = ""; } fileName = valuePart; } if (leftPart.StartsWith("title")) { infoLine = valuePart; } else { if (infoLine == "") infoLine = Path.GetFileName(fileName); } if (leftPart.StartsWith("length")) { durationLine = valuePart; } if (leftPart == "playlistname") { playlist.Name = valuePart; } if (durationLine.Length > 0 && infoLine.Length > 0 && fileName.Length > 0) { int duration = System.Int32.Parse(durationLine); duration *= 1000; string tmp = fileName.ToLowerInvariant(); PlayListItem newItem = new PlayListItem(infoLine, fileName, duration); if (tmp.IndexOf("http:") < 0 && tmp.IndexOf("mms:") < 0 && tmp.IndexOf("rtp:") < 0) { SetupTv.Utils.GetQualifiedFilename(basePath, ref fileName); newItem.Type = PlayListItem.PlayListItemType.AudioStream; } playlist.Add(newItem); fileName = ""; infoLine = ""; durationLine = ""; } } line = file.ReadLine(); } file.Close(); if (fileName.Length > 0) { new PlayListItem(infoLine, fileName, 0); } return true; }
/// <summary> /// Save the current playlist /// </summary> private void saveSmartDJPlaylist() { string playlistFileName = string.Empty; if (GetKeyboard(ref playlistFileName)) { string playListPath = string.Empty; // Have we out own playlist folder configured if (!string.IsNullOrEmpty(mvCentralCore.Settings.PlayListFolder.Trim())) playListPath = mvCentralCore.Settings.PlayListFolder; else { // No, so use my videos location using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) { playListPath = xmlreader.GetValueAsString("movies", "playlists", string.Empty); playListPath = MediaPortal.Util.Utils.RemoveTrailingSlash(playListPath); } playListPath = MediaPortal.Util.Utils.RemoveTrailingSlash(playListPath); } // check if Playlist folder exists, create it if not if (!Directory.Exists(playListPath)) { try { Directory.CreateDirectory(playListPath); } catch (Exception e) { logger.Info("Error: Unable to create Playlist path: " + e.Message); return; } } string fullPlayListPath = Path.GetFileNameWithoutExtension(playlistFileName); fullPlayListPath += ".mvplaylist"; if (playListPath.Length != 0) { fullPlayListPath = playListPath + @"\" + fullPlayListPath; } PlayList playlist = new PlayList(); for (int i = 0; i < facadeLayout.Count; ++i) { GUIListItem listItem = facadeLayout[i]; PlayListItem playListItem = new PlayListItem(); DBTrackInfo mv = (DBTrackInfo)listItem.MusicTag; playListItem.Track = mv; playlist.Add(playListItem); } PlayListIO saver = new PlayListIO(); saver.Save(playlist, fullPlayListPath); } }
protected void LoadPlayList(string strPlayList, bool startPlayback, bool isAsynch, bool defaultLoad) { IPlayListIO loader = PlayListFactory.CreateIO(strPlayList); if (loader == null) { return; } PlayList playlist = new PlayList(); if (!Util.Utils.FileExistsInCache(strPlayList)) { Log.Info("Playlist: Skipping non-existing Playlist file: {0}", strPlayList); return; } if (!loader.Load(playlist, strPlayList)) { if (isAsynch && defaultLoad) // we might not be in GUI yet! we have asynch and default load because we might want to use asynch loading from gui button too, later! throw new Exception(string.Format("Unable to load Playlist file: {0}", strPlayList)); // exception is handled in backgroundworker else TellUserSomethingWentWrong(); return; } if (_autoShuffleOnLoad) { playlist.Shuffle(); } playlistPlayer.CurrentPlaylistName = Path.GetFileNameWithoutExtension(strPlayList); if (playlist.Count == 1 && startPlayback) { Log.Info("GUIMusic:Play: play single playlist item - {0}", playlist[0].FileName); // Default to type Music, when a playlist has been selected from My Music g_Player.Play(playlist[0].FileName, g_Player.MediaType.Music); return; } if (null != bw && isAsynch && bw.CancellationPending) return; // clear current playlist //playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC).Clear(); Song song = new Song(); PlayList newPlaylist = new PlayList(); // add each item of the playlist to the playlistplayer for (int i = 0; i < playlist.Count; ++i) { if (null != bw && isAsynch && bw.CancellationPending) return; PlayListItem playListItem = playlist[i]; m_database.GetSongByFileName(playListItem.FileName, ref song); MusicTag tag = new MusicTag(); tag = song.ToMusicTag(); playListItem.MusicTag = tag; if (Util.Utils.FileExistsInCache(playListItem.FileName) || playListItem.Type == PlayListItem.PlayListItemType.AudioStream) { newPlaylist.Add(playListItem); } else { Log.Info("Playlist: File {0} no longer exists. Skipping item.", playListItem.FileName); } } if (null != bw && isAsynch && bw.CancellationPending) return; ReplacePlaylist(newPlaylist); if (startPlayback) StartPlayingPlaylist(); }
public bool Load(PlayList playlist, string fileName, string label) { string basePath = String.Empty; Stream stream; if (fileName.ToLowerInvariant().StartsWith("http")) { // We've got a URL pointing to a pls WebClient client = new WebClient(); client.Proxy.Credentials = CredentialCache.DefaultCredentials; byte[] buffer = client.DownloadData(fileName); stream = new MemoryStream(buffer); } else { // We've got a plain pls file basePath = Path.GetDirectoryName(Path.GetFullPath(fileName)); stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); } playlist.Clear(); playlist.Name = Path.GetFileName(fileName); Encoding fileEncoding = Encoding.Default; StreamReader file = new StreamReader(stream, fileEncoding, true); try { if (file == null) { return false; } string line; line = file.ReadLine(); if (line == null) { file.Close(); return false; } string strLine = line.Trim(); //CUtil::RemoveCRLF(strLine); if (strLine != START_PLAYLIST_MARKER) { if (strLine.StartsWith("http") || strLine.StartsWith("HTTP") || strLine.StartsWith("mms") || strLine.StartsWith("MMS") || strLine.StartsWith("rtp") || strLine.StartsWith("RTP")) { PlayListItem newItem = new PlayListItem(strLine, strLine, 0); newItem.Type = PlayListItem.PlayListItemType.AudioStream; playlist.Add(newItem); file.Close(); return true; } fileEncoding = Encoding.Default; stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); file = new StreamReader(stream, fileEncoding, true); //file.Close(); //return false; } string infoLine = ""; string durationLine = ""; fileName = ""; line = file.ReadLine(); while (line != null) { strLine = line.Trim(); //CUtil::RemoveCRLF(strLine); int equalPos = strLine.IndexOf("="); if (equalPos > 0) { string leftPart = strLine.Substring(0, equalPos); equalPos++; string valuePart = strLine.Substring(equalPos); leftPart = leftPart.ToLowerInvariant(); if (leftPart.StartsWith("file")) { if (valuePart.Length > 0 && valuePart[0] == '#') { line = file.ReadLine(); continue; } if (fileName.Length != 0) { PlayListItem newItem = new PlayListItem(infoLine, fileName, 0); playlist.Add(newItem); fileName = ""; infoLine = ""; durationLine = ""; } fileName = valuePart; } if (leftPart.StartsWith("title")) { infoLine = valuePart; } else { if (infoLine == "") { // For a URL we need to set the label in for the Playlist name, in order to be played. if (label != null && fileName.ToLowerInvariant().StartsWith("http")) { infoLine = label; } else { infoLine = Path.GetFileName(fileName); } } } if (leftPart.StartsWith("length")) { durationLine = valuePart; } if (leftPart == "playlistname") { playlist.Name = valuePart; } if (durationLine.Length > 0 && infoLine.Length > 0 && fileName.Length > 0) { int duration = Int32.Parse(durationLine); // Remove trailing slashes. Might cause playback issues if (fileName.EndsWith("/")) { fileName = fileName.Substring(0, fileName.Length - 1); } PlayListItem newItem = new PlayListItem(infoLine, fileName, duration); if (fileName.ToLowerInvariant().StartsWith("http:") || fileName.ToLowerInvariant().StartsWith("https:") || fileName.ToLowerInvariant().StartsWith("mms:") || fileName.ToLowerInvariant().StartsWith("rtp:")) { newItem.Type = PlayListItem.PlayListItemType.AudioStream; } else { Util.Utils.GetQualifiedFilename(basePath, ref fileName); newItem.FileName = fileName; newItem.Type = PlayListItem.PlayListItemType.Audio; } playlist.Add(newItem); fileName = ""; infoLine = ""; durationLine = ""; } } line = file.ReadLine(); } file.Close(); if (fileName.Length > 0) { PlayListItem newItem = new PlayListItem(infoLine, fileName, 0); } } finally { if (file != null) { file.Close(); } } return true; }
/// <summary> /// Save player state (when form was resized) /// </summary> protected void SavePlayerState() { // Is App not minimized to tray and is a player active? if (WindowState != FormWindowState.Minimized && !_wasPlayingVideo && (g_Player.Playing && (g_Player.IsTV || g_Player.IsVideo || g_Player.IsDVD))) { _wasPlayingVideo = true; _fullscreen = g_Player.FullScreen; // Some Audio/video is playing _currentPlayerPos = g_Player.CurrentPosition; _currentPlayListType = playlistPlayer.CurrentPlaylistType; _currentPlayList = new PlayList(); Log.Info("D3D: Saving fullscreen state for resume: {0}", _fullscreen); PlayList tempList = playlistPlayer.GetPlaylist(_currentPlayListType); if (tempList.Count == 0 && g_Player.IsDVD == true) { // DVD is playing PlayListItem itemDVD = new PlayListItem(); itemDVD.FileName = g_Player.CurrentFile; itemDVD.Played = true; itemDVD.Type = PlayListItem.PlayListItemType.DVD; tempList.Add(itemDVD); } if (tempList != null) { for (int i = 0; i < (int)tempList.Count; ++i) { PlayListItem itemNew = tempList[i]; _currentPlayList.Add(itemNew); } } _strCurrentFile = playlistPlayer.Get(playlistPlayer.CurrentSong); if (_strCurrentFile.Equals(string.Empty) && g_Player.IsDVD == true) { _strCurrentFile = g_Player.CurrentFile; } Log.Info( "D3D: Form resized - Stopping media - Current playlist: Type: {0} / Size: {1} / Current item: {2} / Filename: {3} / Position: {4}", _currentPlayListType, _currentPlayList.Count, playlistPlayer.CurrentSong, _strCurrentFile, _currentPlayerPos); g_Player.Stop(); _iActiveWindow = GUIWindowManager.ActiveWindow; } }
public void AddItemToPlayList(GUIListItem pItem, ref PlayList playList,VideoInfo qa) { if (playList == null || pItem == null) return; string PlayblackUrl = ""; YouTubeEntry vid; LocalFileStruct file = pItem.MusicTag as LocalFileStruct; if (file != null) { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId); Video video = Youtube2MP.request.Retrieve<Video>(videoEntryUrl); vid = video.YouTubeEntry; } else { vid = pItem.MusicTag as YouTubeEntry; } if (vid != null) { if (vid.Media.Contents.Count > 0) { PlayblackUrl = string.Format("http://www.youtube.com/v/{0}", Youtube2MP.getIDSimple(vid.Id.AbsoluteUri)); } else { PlayblackUrl = vid.AlternateUri.ToString(); } PlayListItem playlistItem = new PlayListItem(); playlistItem.Type = PlayListItem.PlayListItemType.VideoStream;// Playlists.PlayListItem.PlayListItemType.Audio; qa.Entry = vid; playlistItem.FileName = PlayblackUrl; playlistItem.Description = pItem.Label; playlistItem.Duration = pItem.Duration; playlistItem.MusicTag = qa; playList.Add(playlistItem); } }
protected virtual void OnNewRenderingJob(object sender, EventArgs args) { PlayList playlist = new PlayList(); TreePath[] paths = playerstreeview.Selection.GetSelectedRows(); foreach(var path in paths) { TreeIter iter; playerstreeview.Model.GetIter(out iter, path); playlist.Add(new PlayListPlay((Play)playerstreeview.Model.GetValue(iter, 0), Project.Description.File, 1, true)); } if (RenderPlaylistEvent != null) RenderPlaylistEvent(playlist); }
public void AddItemToPlayList(YouTubeEntry vid, ref PlayList playList) { if (playList == null || vid == null) return; string PlayblackUrl = ""; GUIListItem pItem = new GUIListItem(vid.Title.Text); pItem.MusicTag = vid; try { pItem.Duration = Convert.ToInt32(vid.Duration.Seconds); } catch (Exception) { } try { PlayblackUrl = vid.AlternateUri.ToString(); if (vid.Media != null && vid.Media.Contents != null && vid.Media.Contents.Count > 0) { PlayblackUrl = string.Format("http://www.youtube.com/v/{0}", Youtube2MP.getIDSimple(vid.Id.AbsoluteUri)); } } catch (Exception) { return; } VideoInfo qa = new VideoInfo(); PlayListItem playlistItem = new PlayListItem(); playlistItem.Type = PlayListItem.PlayListItemType.VideoStream; // Playlists.PlayListItem.PlayListItemType.Audio; qa.Entry = vid; playlistItem.FileName = PlayblackUrl; playlistItem.Description = pItem.Label; playlistItem.Duration = pItem.Duration; playlistItem.MusicTag = qa; playList.Add(playlistItem); }