Ejemplo n.º 1
0
        /// <summary>
        /// Event for watching when videos finish
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MediaPlayer_MediaEnded(object sender, RoutedEventArgs e)
        {
            // Get the current video path
            string file = this.MediaPlayer.Source.LocalPath;

            // Try to stop it and set the source to null
            try
            {
                this.MediaPlayer.Stop();
            }
            catch { }
            this.MediaPlayer.Source = null;
            // Try to dump the file and set the string storing previous song to where we stored this
            try
            {
                if (videofile != null)
                {
                    if (videofile != string.Empty)
                    {
                        if (System.IO.Path.GetFileName(videofile) != System.IO.Path.GetFileName(this.MediaPlayer.Source.AbsoluteUri))
                        {
                            Task.Run(() => FileFunctions.DeleteTmpFile(file));
                        }
                    }
                }
                videofile = this.MediaPlayer.Source.OriginalString;
            }
            catch { }
            // Queue the next song and hit play
            SongFunctions.Queueevent(this, hidb, db, discordclient, conf);
            this.MediaPlayer.Play();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove the song by a user rather than the song ID
        /// </summary>
        /// <param name="user">The sockeruser to search for</param>
        /// <param name="db">The Queue DB</param>
        /// <returns>Returns the song removed</returns>
        public static string RemoveSongBySongUser(SocketUser user, LiteDatabase db)
        {
            // Find songs by the user
            var queuedb = db.GetCollection <Song>("Queue");
            var results = queuedb.Find(x => x.RequesterId == user.Id);

            // Remove the song if we find it and delete the file if its in the queue
            if (results.Count() >= 1)
            {
                FileFunctions.DeleteTmpFile(results.First().File);
                string title = results.First().Title;
                queuedb.Delete(results.First().Id);
                return(title);
            }
            return("");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Event to watch for new videos
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MediaPlayer_SourceOpened(object sender, RoutedEventArgs e)
 {
     try
     {
         // Compared if we havent checked against anything
         if (videofile != null)
         {
             if (videofile != string.Empty)
             {
                 // Delete the file if it already exists
                 if (System.IO.Path.GetFileName(videofile) != System.IO.Path.GetFileName(this.MediaPlayer.Source.AbsoluteUri))
                 {
                     Task.Run(() => FileFunctions.DeleteTmpFile(videofile));
                 }
             }
         }
         // Set the last video to the source
         videofile = this.MediaPlayer.Source.OriginalString;
     }
     catch { }
 }