elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  [C#] DH Player 1.0
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [C#] DH Player 1.0  (Leído 1,620 veces)
BigBear


Desconectado Desconectado

Mensajes: 545



Ver Perfil
[C#] DH Player 1.0
« en: 13 Marzo 2015, 15:16 pm »

Este vez les traigo un reproductor de musica y peliculas que hice en C# usando WPF con las siguientes opciones :

  • Reproduce musica y videos a pantalla completa
  • Soporta Drag and Drop para reproducir canciones y videos
  • Pueden subir volumen y poner la posicion que quieran
  • Tienen opcion para repetir una cancion o reproducir una carpeta entera automaticamente
  • Pueden poner mute

* Formatos de musica soportados : mp3,m4a,wma
* Formato de videos soportados : avi,mp4,flv,mkv,wmv,mpg

Una imagen :



El codigo

Código
  1. // DH Player 1.0
  2. // (C) Doddy Hackman 2015
  3. // Credits :
  4. // Based on : MP3 Happy Hard Core Player V 1.0 By Steel Karpov
  5. // Thanks to Steel Karpov
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using Microsoft.Win32;
  20. using System.IO;
  21. using System.Windows.Threading;
  22. using System.Text.RegularExpressions;
  23.  
  24. namespace DH_Player
  25. {
  26.    /// <summary>
  27.    /// Lógica de interacción para MainWindow.xaml
  28.    /// </summary>
  29.    public partial class MainWindow : Window
  30.    {
  31.        DispatcherTimer control_del_tiempo;
  32.        bool escribiendo;
  33.        bool enalgo;
  34.        bool repeat;
  35.        bool automatic;
  36.        bool pantalla_completa = false;
  37.  
  38.        public MainWindow()
  39.        {
  40.            InitializeComponent();
  41.  
  42.            control_del_tiempo = new DispatcherTimer();
  43.            control_del_tiempo.Interval = TimeSpan.FromSeconds(1);
  44.            control_del_tiempo.Tick += new EventHandler(timer_Tick);
  45.            escribiendo = false;
  46.        }
  47.  
  48.        private void timer_Tick(object sender, EventArgs e)
  49.        {
  50.            if (!escribiendo)
  51.            {
  52.                linea.Value = player.Position.TotalSeconds;
  53.            }
  54.        }
  55.  
  56.        private void retroceder_MouseUp(object sender, MouseButtonEventArgs e)
  57.        {
  58.            if (lista.SelectedIndex != -1)
  59.            {
  60.                cancion_anterior();
  61.            }
  62.        }
  63.  
  64.        private void play_MouseUp(object sender, MouseButtonEventArgs e)
  65.        {
  66.            if (lista.SelectedIndex != -1)
  67.            {
  68.                enalgo = true;
  69.                player.Play();
  70.            }
  71.        }
  72.  
  73.        private void pause_MouseUp(object sender, MouseButtonEventArgs e)
  74.        {
  75.            if (lista.SelectedIndex != -1)
  76.            {
  77.                player.Pause();
  78.                enalgo = false;
  79.            }
  80.        }
  81.  
  82.        private void avanzar_MouseUp(object sender, MouseButtonEventArgs e)
  83.        {
  84.            if (lista.SelectedIndex != -1)
  85.            {
  86.                cancion_siguiente();
  87.            }
  88.        }
  89.  
  90.        private void nombres_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  91.        {
  92.            if (lista.SelectedIndex != -1)
  93.            {
  94.                enalgo = false;
  95.                start_music();
  96.            }
  97.        }
  98.  
  99.        private void start_music()
  100.        {
  101.  
  102.            if (enalgo == true)
  103.            {
  104.                player.Play();
  105.            }
  106.            else
  107.            {
  108.  
  109.                ListBoxItem ruta1 = (ListBoxItem)lista.SelectedItem;
  110.                string ruta = ruta1.Tag.ToString();
  111.                player.Position = TimeSpan.Zero;
  112.                player.LoadedBehavior = MediaState.Manual;
  113.                player.UnloadedBehavior = MediaState.Stop;
  114.                player.Source = new Uri(ruta);
  115.                linea.Value = 0;
  116.                player.Play();
  117.            }
  118.        }
  119.  
  120.        private void cancion_siguiente()
  121.        {
  122.            enalgo = false;
  123.  
  124.            try
  125.            {
  126.  
  127.                if (lista.SelectedIndex + 1 < lista.Items.Count)
  128.                {
  129.                    lista.SelectedItem = lista.Items.GetItemAt(lista.SelectedIndex + 1);
  130.                    start_music();
  131.                }
  132.  
  133.            }
  134.  
  135.            catch
  136.            {
  137.                //
  138.            }
  139.        }
  140.  
  141.        private void cancion_anterior()
  142.        {
  143.            enalgo = false;
  144.  
  145.            try
  146.            {
  147.  
  148.                if (lista.SelectedIndex - 1 < lista.Items.Count)
  149.                {
  150.                    lista.SelectedItem = lista.Items.GetItemAt(lista.SelectedIndex - 1);
  151.                    start_music();
  152.                }
  153.  
  154.            }
  155.  
  156.            catch
  157.            {
  158.                //
  159.            }
  160.        }
  161.  
  162.        private void volumen_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  163.        {
  164.            try
  165.            {
  166.                player.Volume = volumen.Value;
  167.            }
  168.            catch
  169.            {
  170.                //
  171.            }
  172.        }
  173.  
  174.        private void player_MouseDown(object sender, MouseButtonEventArgs e)
  175.        {
  176.  
  177.            int width_screen = 1400;
  178.            int height_screen = 800;
  179.  
  180.            int width_original = 483;
  181.            int height_original = 372;
  182.  
  183.            if (e.ClickCount == 2 && pantalla_completa == false)
  184.            {
  185.                player.MinHeight = height_screen;
  186.                player.MinWidth = width_screen;
  187.  
  188.                volumen.Visibility = Visibility.Hidden;
  189.                linea.Visibility = Visibility.Hidden;
  190.                play.Visibility = Visibility.Hidden;
  191.                pause.Visibility = Visibility.Hidden;
  192.                avanzar.Visibility = Visibility.Hidden;
  193.                retroceder.Visibility = Visibility.Hidden;
  194.                contenedor1.Visibility = Visibility.Hidden;
  195.                contenedor2.Visibility = Visibility.Hidden;
  196.                lista.Visibility = Visibility.Hidden;
  197.                menu1.Visibility = Visibility.Hidden;
  198.                progreso.Visibility = Visibility.Hidden;
  199.                this.WindowStyle = WindowStyle.None;
  200.                this.WindowState = WindowState.Maximized;
  201.  
  202.                pantalla_completa = true;
  203.  
  204.            }
  205.            else
  206.            {
  207.  
  208.                if (e.ClickCount == 2 && pantalla_completa == true)
  209.                {
  210.                    player.MinHeight = height_original;
  211.                    player.MinWidth = width_original;
  212.  
  213.                    volumen.Visibility = Visibility.Visible;
  214.                    linea.Visibility = Visibility.Visible;
  215.                    play.Visibility = Visibility.Visible;
  216.                    pause.Visibility = Visibility.Visible;
  217.                    avanzar.Visibility = Visibility.Visible;
  218.                    retroceder.Visibility = Visibility.Visible;
  219.                    contenedor1.Visibility = Visibility.Visible;
  220.                    contenedor2.Visibility = Visibility.Visible;
  221.                    lista.Visibility = Visibility.Visible;
  222.                    menu1.Visibility = Visibility.Visible;
  223.                    progreso.Visibility = Visibility.Visible;
  224.                    this.WindowStyle = WindowStyle.SingleBorderWindow;
  225.                    this.WindowState = WindowState.Normal;
  226.  
  227.                    pantalla_completa = false;
  228.  
  229.                }
  230.            }
  231.  
  232.        }
  233.  
  234.        private void player_MediaOpened(object sender, RoutedEventArgs e)
  235.        {
  236.  
  237.            enalgo = true;
  238.  
  239.            if (player.NaturalDuration.HasTimeSpan)
  240.            {
  241.                TimeSpan ts = player.NaturalDuration.TimeSpan;
  242.                linea.Maximum = ts.TotalSeconds;
  243.                linea.SmallChange = 1;
  244.            }
  245.  
  246.            control_del_tiempo.Start();
  247.        }
  248.  
  249.        private void player_MediaEnded(object sender, RoutedEventArgs e)
  250.        {
  251.            linea.Value = 0;
  252.            enalgo = false;
  253.            if (repeat == true)
  254.            {
  255.                start_music();
  256.            }
  257.            if (automatic == true)
  258.            {
  259.                cancion_siguiente();
  260.            }
  261.        }
  262.  
  263.        private void linea_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  264.        {
  265.            escribiendo = true;
  266.        }
  267.  
  268.        private void linea_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  269.        {
  270.            escribiendo = false;
  271.            player.Position =
  272.                TimeSpan.FromSeconds(linea.Value);
  273.        }
  274.  
  275.        private void linea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  276.        {
  277.            player.Position = TimeSpan.FromSeconds(linea.Value);
  278.        }
  279.  
  280.        private void linea_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  281.        {
  282.            try
  283.            {
  284.                string tiempo = TimeSpan.FromSeconds(linea.Value).ToString();
  285.                int cantidad = (int)player.NaturalDuration.TimeSpan.TotalSeconds;
  286.  
  287.                TimeSpan tiempo_final = TimeSpan.FromSeconds(cantidad);
  288.  
  289.                Match regex = Regex.Match(tiempo, @"(.*)\.(.*)", RegexOptions.IgnoreCase);
  290.                if (regex.Success)
  291.                {
  292.                    progreso.Content = regex.Groups[1].Value + " / " + tiempo_final;
  293.                }
  294.            }
  295.            catch
  296.            {
  297.                //
  298.            }
  299.        }
  300.  
  301.        private void nombres_DragEnter(object sender, DragEventArgs e)
  302.        {
  303.            if (e.Data.GetDataPresent(DataFormats.FileDrop))
  304.            {
  305.                e.Effects = DragDropEffects.Copy;
  306.            }
  307.            else
  308.            {
  309.                e.Effects = DragDropEffects.None;
  310.            }
  311.        }
  312.  
  313.        private void nombres_Drop(object sender, DragEventArgs e)
  314.        {
  315.            List<string> archivos = new List<string>((string[])e.Data.GetData(DataFormats.FileDrop));
  316.            foreach (string archivo in archivos)
  317.            {
  318.                string nombre = System.IO.Path.GetFileNameWithoutExtension(archivo);
  319.                string extension = System.IO.Path.GetExtension(archivo);
  320.                if (extension == ".mp3" || extension == ".avi" || extension==".m4a" || extension==".wma" || extension==".mp4" || extension==".flv" || extension==".mkv" || extension==".wmv" || extension==".mpg")
  321.                {
  322.                    ListBoxItem item1 = new ListBoxItem();
  323.                    item1.Content = nombre;
  324.                    item1.Tag = archivo;
  325.                    lista.Items.Add(item1);
  326.                }
  327.            }
  328.        }
  329.  
  330.        private void MenuItem_Click(object sender, RoutedEventArgs e)
  331.        {
  332.            OpenFileDialog openFileDialog1 = new OpenFileDialog();
  333.            openFileDialog1.Filter = "MP3 (.mp3)|*.mp3|M4A (.m4a)|*.m4a|WMA (.wma)|*.m4a";
  334.            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  335.            openFileDialog1.Multiselect = true;
  336.            openFileDialog1.Title = "Select Song";
  337.            Nullable<bool> result = openFileDialog1.ShowDialog();
  338.            if (result == true)
  339.            {
  340.  
  341.                string[] archivos = openFileDialog1.FileNames;
  342.                foreach (string archivo in archivos)
  343.                {
  344.                    string nombre = System.IO.Path.GetFileNameWithoutExtension(archivo);
  345.                    ListBoxItem item1 = new ListBoxItem();
  346.                    item1.Content = nombre;
  347.                    item1.Tag = archivo;
  348.                    lista.Items.Add(item1);
  349.                }
  350.            }
  351.        }
  352.  
  353.        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
  354.        {
  355.            OpenFileDialog openFileDialog1 = new OpenFileDialog();
  356.            openFileDialog1.Filter = "MP3 (.mp3)|*.mp3|M4A (.m4a)|*.m4a|WMA (.wma)|*.m4a";
  357.            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  358.            openFileDialog1.Multiselect = true;
  359.            openFileDialog1.Title = "Select Song";
  360.            Nullable<bool> result = openFileDialog1.ShowDialog();
  361.            if (result == true)
  362.            {
  363.                string directorio = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
  364.                string[] archivos = Directory.GetFiles(directorio);
  365.                foreach (string archivo in archivos)
  366.                {
  367.                    string extension = System.IO.Path.GetExtension(archivo);
  368.                    if (extension == ".mp3" || extension == ".m4a" || extension==".wma")
  369.                    {
  370.                        string nombre = System.IO.Path.GetFileNameWithoutExtension(archivo);
  371.                        ListBoxItem item1 = new ListBoxItem();
  372.                        item1.Content = nombre;
  373.                        item1.Tag = archivo;
  374.                        lista.Items.Add(item1);
  375.                    }
  376.                }
  377.            }
  378.        }
  379.  
  380.        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
  381.        {
  382.            OpenFileDialog openFileDialog1 = new OpenFileDialog();
  383.            openFileDialog1.Filter = "avi (.avi)|*.avi|mp4 (.mp4)|*.mp4|flv (.flv)|*.flv|mkv (.mkv)|*.mkv|wmv (.wmv)|*.wmv|mpg (.mpg)|*.mpg";
  384.            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  385.            openFileDialog1.Multiselect = true;
  386.            openFileDialog1.Title = "Select Video";
  387.            Nullable<bool> result = openFileDialog1.ShowDialog();
  388.            if (result == true)
  389.            {
  390.                string[] archivos = openFileDialog1.FileNames;
  391.                foreach (string archivo in archivos)
  392.                {
  393.                    string nombre = System.IO.Path.GetFileNameWithoutExtension(archivo);
  394.                    ListBoxItem item1 = new ListBoxItem();
  395.                    item1.Content = nombre;
  396.                    item1.Tag = archivo;
  397.                    lista.Items.Add(item1);
  398.                }
  399.            }
  400.        }
  401.  
  402.        private void MenuItem_Click_3(object sender, RoutedEventArgs e)
  403.        {
  404.            OpenFileDialog openFileDialog1 = new OpenFileDialog();
  405.            openFileDialog1.Filter = "avi (.avi)|*.avi|mp4 (.mp4)|*.mp4|flv (.flv)|*.flv|mkv (.mkv)|*.mkv|wmv (.wmv)|*.wmv|mpg (.mpg)|*.mpg";
  406.            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  407.            openFileDialog1.Multiselect = true;
  408.            openFileDialog1.Title = "Select Videos";
  409.            Nullable<bool> result = openFileDialog1.ShowDialog();
  410.            if (result == true)
  411.            {
  412.                string directorio = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
  413.                string[] archivos = Directory.GetFiles(directorio);
  414.                foreach (string archivo in archivos)
  415.                {
  416.                    string extension = System.IO.Path.GetExtension(archivo);
  417.                    if (extension == ".avi" || extension==".mp4" || extension ==".flv" || extension==".mkv" || extension ==".wmv" || extension==".mpg")
  418.                    {
  419.                        string nombre = System.IO.Path.GetFileNameWithoutExtension(archivo);
  420.                        ListBoxItem item1 = new ListBoxItem();
  421.                        item1.Content = nombre;
  422.                        item1.Tag = archivo;
  423.                        lista.Items.Add(item1);
  424.                    }
  425.                }
  426.            }
  427.        }
  428.  
  429.        private void MenuItem_Click_4(object sender, RoutedEventArgs e)
  430.        {
  431.            repeat = true;
  432.        }
  433.  
  434.        private void MenuItem_Click_5(object sender, RoutedEventArgs e)
  435.        {
  436.            repeat = false;
  437.        }
  438.  
  439.        private void MenuItem_Click_6(object sender, RoutedEventArgs e)
  440.        {
  441.            automatic = true;
  442.        }
  443.  
  444.        private void MenuItem_Click_7(object sender, RoutedEventArgs e)
  445.        {
  446.            automatic = false;
  447.        }
  448.  
  449.        private void MenuItem_Click_10(object sender, RoutedEventArgs e)
  450.        {
  451.            player.IsMuted = true;
  452.        }
  453.  
  454.        private void MenuItem_Click_11(object sender, RoutedEventArgs e)
  455.        {
  456.            player.IsMuted = false;
  457.        }
  458.  
  459.        private void MenuItem_Click_8(object sender, RoutedEventArgs e)
  460.        {
  461.            MessageBox.Show("Written By Doddy Hackman in the summer of 2015");
  462.        }
  463.  
  464.        private void MenuItem_Click_9(object sender, RoutedEventArgs e)
  465.        {
  466.            Application.Current.Shutdown();
  467.        }
  468.  
  469.        private void MenuItem_Click_12(object sender, RoutedEventArgs e)
  470.        {
  471.            lista.Items.Clear();
  472.        }
  473.  
  474.    }
  475. }
  476.  
  477. // The End ?
  478.  

Si quieren bajar el programa lo pueden hacer de aca :

SourceForge.
Github.

Eso es todo.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
real player one
Multimedia
N.P.I. 4 2,988 Último mensaje 19 Enero 2004, 18:17 pm
por Songoku
dvd player
Multimedia
HpMaxi 1 1,588 Último mensaje 10 Marzo 2006, 07:51 am
por Sourraund
FLV Player v2.0.24
Multimedia
MicroAttackeR 0 2,186 Último mensaje 27 Octubre 2008, 18:41 pm
por MicroAttackeR
VMware Player 3.1.3. Crea y ejecuta máquinas virtuales con VMware Player
Software
wolfbcn 0 4,104 Último mensaje 23 Noviembre 2010, 21:11 pm
por wolfbcn
Car mp3/mp4 player
Dispositivos Móviles (PDA's, Smartphones, Tablets)
pardo 0 1,799 Último mensaje 8 Noviembre 2011, 20:46 pm
por pardo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines