Ejemplo n.º 1
0
        public MainViewModel(MainWindowViewModel model, PlaylistViewModel playlist)
        {
            _nextcmd = new RelayCommand(NextCmd, CanNext);
            _previouscmd = new RelayCommand(PreviousCmd, CanPrevious);
            _playlistcmd = new RelayCommand(PlaylistCmd, () => true);
            _playcmd = new RelayCommand(PlayCmd, () => true);
            _repeatcmd = new RelayCommand(RepeatCmd, () => true);
            _randcmd = new RelayCommand(RandCmd, () => true);
            _stopcmd = new RelayCommand(StopCmd, () => true);
            _fullscreencmd = new RelayCommand(FullScreenCmd, CanFullScreen);
            _exitfullscreencmd = new RelayCommand(ExitFullScreenCmd, () => true);
            _changevolumecmd = new RelayCommand(ChangeVolumeCmd, () => true);
            _mediainfoscmd = new RelayCommand(MediaInfosCmd, CanMediaInfos);

            _typeFilter = WMP.Model.MediaFilter.TITLE;
            _playmediacmd = new RelayCommand(playMediaCmd, () => true);
            _addvideoscmd = new RelayCommand(addVideoCmd, () => true);
            _addsongscmd = new RelayCommand(addSongCmd, () => true);
            _addpicturescmd = new RelayCommand(addPictureCmd, () => true);
            _addsongtoplaylist = new RelayCommand(addSongToPlayList, () => true);
            _addvideotoplaylist = new RelayCommand(addVideoToPlayList, () => true);
            _addpicturetoplaylist = new RelayCommand(addPictureToPlayList, () => true);
            _deletevideocmd = new RelayCommand(deleteVideoCmd, () => true);
            _deletesongcmd = new RelayCommand(deleteSongCmd, () => true);
            _deletepicturecmd = new RelayCommand(deletePictureCmd, () => true);
            _clearvideos = new RelayCommand(clearVideos, () => true);
            _clearpictures = new RelayCommand(clearPictures, () => true);
            _clearsongs = new RelayCommand(clearSongs, () => true);
            _clearallcmd = new RelayCommand(clearAll, () => true);

            ListVideos = new ObservableCollection<VideoMedia>();
            ListSongs = new ObservableCollection<AudioMedia>();
            ListPictures = new ObservableCollection<PictureMedia>();

            _rand = 0;
            _playlist = playlist;
            _isRandEnabled = false;
            _repeatState = repeatStatus.NONE    ;
            _model = model;
            _media = null;
            _search = "";
            _mediaInfosOpen = false;
            _mediaInfos = new Window[(int)t_MediaType.NONE];
            _mediaInfos[(int)t_MediaType.AUDIO] = null;
            _mediaInfos[(int)t_MediaType.VIDEO] = null;
            _mediaInfos[(int)t_MediaType.PICTURE] = null;
            _mediaInfosFillers = new Action[(int)t_MediaType.NONE];
            _mediaInfosFillers[(int)t_MediaType.AUDIO] = new Action(FillAudioModel);
            _mediaInfosFillers[(int)t_MediaType.VIDEO] = new Action(FillVideoModel);
            _mediaInfosFillers[(int)t_MediaType.PICTURE] = new Action(FillPictureModel);
            _createMediaWindow = new Func<Window>[(int)t_MediaType.NONE];
            _createMediaWindow[(int)t_MediaType.AUDIO] = new Func<Window>(CreateAudioWindow);
            _createMediaWindow[(int)t_MediaType.VIDEO] = new Func<Window>(CreateVideoWindow);
            _createMediaWindow[(int)t_MediaType.PICTURE] = new Func<Window>(CreatePictureWindow);
            _infosModels = new ViewModelBase[(int)t_MediaType.NONE];
            _infosModels[(int)t_MediaType.AUDIO] = new AudioMediaViewModel();
            _infosModels[(int)t_MediaType.VIDEO] = new VideoMediaViewModel();
            _infosModels[(int)t_MediaType.PICTURE] = new PictureMediaViewModel();
            _fullScreen = false;
            _rnd = new Random();
            _progress = new Timer(200);
            _progress.Elapsed += ProgressElapsed;
            _player = new MediaElement();
            _player.LoadedBehavior = MediaState.Manual;
            _player.MediaOpened += MediaLoaded;
            _player.MediaEnded += OnMediaEnded;
            _player.MediaFailed += OnMediaFailed;

            loadPicturesLibrary();
            loadSongsLibrary();
            loadVideosLibrary();
        }
Ejemplo n.º 2
0
 public void OnAddPlaylist()
 {
     if (_playlist.ListMedia.Count > 0 && _media == null)
     {
         _media = _playlist.ListMedia[0];
         _player.Source = new Uri(_media.FileName);
     }
 }
Ejemplo n.º 3
0
 public void OnOpenMedia(string FileName)
 {
     if (FileName != null)
     {
         Console.WriteLine("FileName : " + FileName);
         try
         {
             _player.Source = new Uri(FileName);
             _player.Play();
         }
         catch (Exception)
         {
             MessageBox.Show("Error occured when trying to open media", "Open error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         if (_media == null)
         {
             _media = Media.CreateMedia(true, FileName, false, ExtensionStatic.GetIconsFromExtension(Path.GetExtension(FileName)));
             _playlist.ListMedia.Add(_media);
         }
         else
         {
             _playlist.ListMedia.Remove(_media);
             _media = Media.CreateMedia(true, FileName, false, ExtensionStatic.GetIconsFromExtension(Path.GetExtension(FileName)));
             _playlist.ListMedia.Add(_media);
         }
     }
 }
Ejemplo n.º 4
0
 private void StopCmd()
 {
     _progress.Stop();
     OnPropertyChanged("ProgressBar");
     if (_playlist.ListMedia.Count > 0)
     {
         _media = _playlist.ListMedia[0];
         _media.isPlaying = false;
         _media.isStopped = true;
         _player.Source = new Uri(_media.FileName);
     }
     _player.Stop();
     if (_fullScreen)
         FullScreenCmd();
     OnPropertyChanged("StopPlay");
 }
Ejemplo n.º 5
0
        private void PreviousCmd()
        {
            bool playingNext = _media.isPlaying;

            if (_isRandEnabled)
                _media = _playlist.ListMedia[_rand];
            else if (_playlist.ListMedia.IndexOf(_media) == 0 && _repeatState == repeatStatus.REPEAT_ALL)
                _media = _playlist.ListMedia[_playlist.ListMedia.Count - 1];
            else if (_repeatState != repeatStatus.REPEAT_ONE)
                _media = _playlist.ListMedia[_playlist.ListMedia.IndexOf(_media) - 1];
            _media.isPlaying = playingNext;
            _player.Source = new Uri(_media.FileName);
            OnPropertyChanged("MediaName");
            OnPropertyChanged("MediaNameNext");
        }
Ejemplo n.º 6
0
        private void playMediaCmd()
        {
            IEnumerable<Media> lv = ListVideos.Where(m => m.IsSelected == true);
            IEnumerable<Media> lm = ListSongs.Where(m => m.IsSelected == true);
            IEnumerable<Media> lp = ListPictures.Where(m => m.IsSelected == true);

            if (lv.Count() > 0)
            {
                _player.Stop();
                _media = lv.ElementAt(0);
                OnOpenMedia(_media.FileName);
            }
            else if (lm.Count() > 0)
            {
                _player.Stop();
                _media = lm.ElementAt(0);
                OnOpenMedia(_media.FileName);
            }
            else if (lp.Count() > 0)
            {
                _player.Stop();
                _media = lp.ElementAt(0);
                OnOpenMedia(_media.FileName);
            }
        }
Ejemplo n.º 7
0
        private void NextCmd()
        {
            bool playingPrev = _media.isPlaying;

            if (_isRandEnabled)
                _media = _playlist.ListMedia[_rand];
            else if (_playlist.ListMedia.IndexOf(_media) == (_playlist.ListMedia.Count - 1) && _repeatState == repeatStatus.REPEAT_ALL)
                _media = _playlist.ListMedia[0];
            else if (_repeatState != repeatStatus.REPEAT_ONE)
                _media = _playlist.ListMedia[_playlist.ListMedia.IndexOf(_media) + 1];
            _media.isPlaying = playingPrev;
            _player.Source = new Uri(_media.FileName);
            if (_playlist.ListMedia.Count == 1)
                MediaLoaded(this, null);
            OnPropertyChanged("MediaName");
            OnPropertyChanged("MediaNameNext");
        }
Ejemplo n.º 8
0
        public static Media CreateMedia(bool isPlaying, string fileName, bool isStopped, string icon)
        {
            t_MediaType type = ExtensionStatic.GetTypeFromExtension(Path.GetExtension(fileName));
            Media media;
            TagLib.File file = null;

            Console.WriteLine(fileName);
            try
            {
                file = TagLib.File.Create(fileName);
            }
            catch (Exception)
            { }
            if (type != t_MediaType.NONE)
                media = createMedia[(int)type](fileName, file);
            else
            {
                media = new Media();
                media.MediaType = t_MediaType.NONE;
                media.Title = Path.GetFileNameWithoutExtension(fileName);
            }
            media.isPlaying = isPlaying;
            media.FileName = fileName;
            media.isStopped = isStopped;
            media.Icon = icon;
            return media;
        }