Monday 9 January 2012

wpf media player

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Forms;


namespace media_Play
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //mediaElement1.Source = new Uri(@"/New Stories (Highway Blues).wma", UriKind.Relative);

            //mediaElement1.Play();
            ////mediaElement1.LoadedBehavior = MediaState.Manual;
            ////mediaElement1.Source = new Uri(@"~\\hum apni taraf.wmv", UriKind.RelativeOrAbsolute);
            ////mediaElement1.Play();


        }



        private void mediaElement1_Loaded(object sender, RoutedEventArgs e)
        {
          
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();

                //  dlg.InitialDirectory = "c:\\";

                dlg.Filter = "Media files (*.wmv)|*.wmv|All Files (*.*)|*.*";
                dlg.Multiselect = true;
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string selectedFileName = dlg.FileName;
                  //  FileNameLabel.Content = selectedFileName;
                    mediaElement1.Source = new Uri(selectedFileName, UriKind.RelativeOrAbsolute);
                   mediaElement1.Play();
                }
            }
            catch (Exception)
            {
              
               // throw;
            }

         
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (mediaElement1.HasAudio|| mediaElement1.HasVideo)
            {
                 mediaElement1.Pause();
            }
          
        

        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            if (mediaElement1.HasAudio || mediaElement1.HasVideo)
            {
                mediaElement1.Play();
            }
        }
  
    }
}


No comments:

Post a Comment