//Affichage du temps
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (monfichier != null)
                {
                    int i = (int)monfichier.CurrentPosition;
                    int min = i / 60;
                    int sec = i % 60;
                    Barre_avancement.Value = i;
                    if (min < 10 && sec < 10)
                    {
                        temps.Text = "0" + min.ToString() + ":0" + sec.ToString();
                    }
                    if (min < 10 && sec > 10)
                    {
                        temps.Text = "0" + min.ToString() + ":" + sec.ToString();
                    }
                    if (sec < 10 && min > 10)
                    {
                        temps.Text = min.ToString() + ":0" + sec.ToString();
                    }
                    if (min > 10 && sec > 10)
                    {
                        temps.Text = min.ToString() + ":" + sec.ToString();
                    }

                    if (monfichier.CurrentPosition >= monfichier.Duration)
                    {
                        monfichier.Stop();
                        if (playlist.ContainsKey(index+1))
                        {
                            index++;
                            try
                            {
                                monfichier = new Audio(playlist[index]);
                            }
                            catch
                            {
                                MessageBox.Show("Fichier invalide", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            RAZslidebar();
                            lister();
                            monfichier.Play();
                        }

                    }
                }
        }
Example #2
0
 private void ClearAudio()
 {
     if (_audio != null)
     {
         _audio.Dispose(); _audio = null;
     }
 }
Example #3
0
 /// <summary>
 /// Stop music that is currently playing and dispose of the song.
 /// Does nothing if no music is playing.
 /// </summary>
 public void Stop()
 {
     if (isPlaying)
     {
         currentSong.Stop();
         currentSong.Dispose();
         currentSong       = null;
         isPlaying         = false;
         lastMusicPosition = 0;
     }
 }
Example #4
0
        private void InitVideo()
        {
            if (checkFileName())
            {
                try
                {
                    if (_video != null)
                    {
                        if (_cachedPath != _filePath)
                        {
                            _video.Dispose();
                            _video      = new Video(_filePath);
                            _cachedPath = _filePath;
                        }
                    }
                    else
                    {
                        _video      = new Video(_filePath);
                        _cachedPath = _filePath;
                    }

                    _video.Owner = VideoPanel;
                    isVideo      = true;
                    if (_audio != null)
                    {
                        _audio.Dispose(); _audio = null;
                    }
                }
                catch
                {
                    if (_audio != null)
                    {
                        if (_cachedPath != _filePath)
                        {
                            _audio.Dispose();
                            _video      = new Video(_filePath);
                            _cachedPath = _filePath;
                        }
                    }
                    else
                    {
                        _audio      = new Audio(_filePath);
                        _cachedPath = _filePath;
                    }
                    isVideo = false;
                    if (_video != null)
                    {
                        _video.Dispose(); _video = null;
                    }
                }
                InitEvents();
            }
        }
Example #5
0
 /// <summary>
 /// Constructs the MP3Player, but does not start playing anything yet.
 /// </summary>
 /// <param name="audioDirectory">Directory on the local hard drive to look
 /// for music from.</param>
 public MP3Player(string audioDirectory)
 {
     this.audioDirectory = audioDirectory;
     lastMusicPosition = 0;
     isPlaying = false;
     currentSong = null;
     playlist = new List<string>();
     playlistPosition = 0;
     playPlaylist = false;
     volume = -1000;
     AutoPlayPlaylist = true;
     LoopCurrentSong = false;
 }
Example #6
0
 /// <summary>
 /// Constructs the MP3Player, but does not start playing anything yet.
 /// </summary>
 /// <param name="audioDirectory">Directory on the local hard drive to look
 /// for music from.</param>
 public MP3Player(string audioDirectory)
 {
     this.audioDirectory = audioDirectory;
     lastMusicPosition   = 0;
     isPlaying           = false;
     currentSong         = null;
     playlist            = new List <string>();
     playlistPosition    = 0;
     playPlaylist        = false;
     volume           = -1000;
     AutoPlayPlaylist = true;
     LoopCurrentSong  = false;
 }
Example #7
0
        /// <summary>
        /// Play the given song.
        /// </summary>
        /// <param name="songName"></param>
        /// <param name="loop"></param>
        /// <returns></returns>
        public bool Play(string songName, bool loop)
        {
            LoopCurrentSong = loop;

            string finalPath;

            songName = songName.Replace("/", @"\");
            if (songName.Contains(@"\"))
            {
                currentSongTitle = songName.Substring(songName.LastIndexOf('\\') + 1);
                finalPath        = songName;
            }
            else
            {
                currentSongTitle = songName;
                finalPath        = Path.Combine(audioDirectory, songName);
            }

            currentSongPath = finalPath;

            try
            {
                currentSong = new Microsoft.DirectX.AudioVideoPlayback.Audio(finalPath);
                currentSong.Play();
                currentSong.Volume  = Volume;
                currentSong.Ending += new EventHandler(OnSongEnding);

                isPlaying = true;
            }
            catch (FileNotFoundException)
            {
                return(false);
            }
            catch (DirectXException)
            {
                return(false);
            }

            return(true);
        }
Example #8
0
 /// <summary>
 /// Stop music that is currently playing and dispose of the song.
 /// Does nothing if no music is playing.
 /// </summary>
 public void Stop()
 {
     if (isPlaying)
     {
         currentSong.Stop();
         currentSong.Dispose();
         currentSong = null;
         isPlaying = false;
         lastMusicPosition = 0;
     }
 }
Example #9
0
        /// <summary>
        /// Play the given song.
        /// </summary>
        /// <param name="songName"></param>
        /// <param name="loop"></param>
        /// <returns></returns>
        public bool Play(string songName, bool loop)
        {
            LoopCurrentSong = loop;

            string finalPath;
            songName = songName.Replace("/", @"\");
            if (songName.Contains(@"\"))
            {
                currentSongTitle = songName.Substring(songName.LastIndexOf('\\') + 1);
                finalPath = songName;
            }
            else
            {
                currentSongTitle = songName;
                finalPath = Path.Combine(audioDirectory, songName);
            }

            currentSongPath = finalPath;

            try
            {
                currentSong = new Microsoft.DirectX.AudioVideoPlayback.Audio(finalPath);
                currentSong.Play();
                currentSong.Volume = Volume;
                currentSong.Ending += new EventHandler(OnSongEnding);

                isPlaying = true;
            }
            catch (FileNotFoundException)
            {
                return false;
            }
            catch (DirectXException)
            {
                return false;
            }

            return true;
        }
 private void toolStripMenuItem1_Click(object sender, EventArgs e)
 {
     OpenFileDialog exploreur = new OpenFileDialog();
     exploreur.Multiselect = true;
     exploreur.Filter = ("Fichier Audio|*.mp3;*.wma;*.wav");
     exploreur.RestoreDirectory = true;
     if (exploreur.ShowDialog() == DialogResult.OK)
     {
         List<string> l = new List<string>();
         l.AddRange(exploreur.FileNames);
         int i = playlist.Count;
         foreach (string s in l)
         {
             playlist.Add(i, s);
             i++;
         }
         if (monfichier == null)
         {
             try
             {
                 monfichier = new Audio(playlist[0]);
             }
             catch
             {
                 MessageBox.Show("Le premier fichier selectionné est invalide", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 if (playlist.Count != 1)
                 {
                     playlist[0] = playlist[playlist.Count - 1];
                 }
                 playlist.Remove(playlist.Count-1);
                 lister();
             }
         }
     }
     lister();
     if (monfichier != null)
         Barre_avancement.Maximum = (int)monfichier.Duration;
 }
        private void suivant()
        {
            if (playlist.Count != 0 && playlist.ContainsKey(index + 1))
            {
                try
                {
                    monfichier.Stop();
                    timer1.Stop();
                    monfichier.Dispose();
                    index++;
                    monfichier = new Audio(playlist[index]);

                }
                catch
                {
                    MessageBox.Show("Fichier invalide", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    supprimer_fichier();
                }
                RAZslidebar();
                lister();
                monfichier.Play();
                timer1.Start();
            }
        }
        //Lancement de fichier par double clik
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if(playlist.ContainsKey(Aff_playlist.SelectedIndices[0]))
                    {
                        if(monfichier!=null)
                        {
                            try
                            {
                                monfichier.Stop();
                                monfichier.Dispose();
                                monfichier = null;
                            }
                            catch
                            {

                            }
                        }

                        index = Aff_playlist.SelectedIndices[0];
                        lister();
                        lancer_fichier();
                    }
        }
        //Remplissage de la playliste
        /*Charge le fichier,lance la lecture et lance le timer*/
        private void lancer_fichier()
        {
            if (monfichier == null)
            {
                if (playlist.ContainsKey(index))
                {
                    try
                    {
                        monfichier = new Audio(playlist[index]);
                        monfichier.Play();
                    }
                    catch
                    {
                        MessageBox.Show("Fichier invalide", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
            }
            else
            {
                if (monfichier == null)
                    textBox3.Text = "il est nul";
                monfichier.Play();

            }
            timer1.Start();
        }
        private void InitVideo()
        {
            if (checkFileName())
            {
                try
                {
                    if (_video != null)
                    {
                        if (_cachedPath != _filePath)
                        {
                            _video.Dispose();
                            _video = new Video(_filePath);
                            _cachedPath = _filePath;
                        }
                    }
                    else
                    {
                        _video = new Video(_filePath);
                        _cachedPath = _filePath;
                    }

                    _video.Owner = VideoPanel;
                    isVideo = true;
                    if (_audio != null) { _audio.Dispose(); _audio = null; }
                }
                catch
                {
                    if (_audio != null)
                    {
                        if (_cachedPath != _filePath)
                        {
                            _audio.Dispose();
                            _video = new Video(_filePath);
                            _cachedPath = _filePath;
                        }
                    }
                    else
                    {
                        _audio = new Audio(_filePath);
                        _cachedPath = _filePath;
                    }
                    isVideo = false;
                    if (_video != null) { _video.Dispose(); _video = null; }
                }
                InitEvents();
            }
        }
 private void ClearAudio()
 {
     if (_audio != null) { _audio.Dispose(); _audio = null; }
 }
Example #16
0
 private void LoadMusic(string filename)
 {
     mAVAudio         = new Microsoft.DirectX.AudioVideoPlayback.Audio(filename);
     mAVAudio.Ending += new EventHandler(mAVAudio_Ending);
 }