Click here to Skip to main content
15,896,348 members
Articles / Desktop Programming / WPF

(Hybrid Smart Client) RSS Media Player

Rate me:
Please Sign up or sign in to vote.
3.92/5 (8 votes)
9 Mar 2009CPOL4 min read 68.7K   1K   17  
A WPF application for viewing RSS video feeds. Built using the MVVM pattern.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RSSVideoPlayer.Model;
using System.Collections.ObjectModel; 
using RSSVideoPlayer.Common;
using System.Windows.Input;
using System.IO;
using Microsoft.Win32;

namespace RSSVideoPlayer.ViewModel
{
    class LibraryViewModel : TabViewModel
    {
        private MediaItem  _MediaItems;
        private Data.LibraryRepository repository;
        public LibraryViewModel()
        {
            repository = new RSSVideoPlayer.Data.LibraryRepository();
            base.TabName = "Library";
         
        }
        public LibraryViewModel(string StartingFolder)
        {
            repository = new RSSVideoPlayer.Data.LibraryRepository(StartingFolder);
            base.TabName = "Library";
        }

        public string FolderPath
        {
            get { return repository.FilePath; }
            set 
            { 
                repository.FilePath = value; 
                repository = new RSSVideoPlayer.Data.LibraryRepository(FolderPath);
                OnPropertyChanged("MediaItems");
            }
        }

        public ObservableCollection<MediaItem> MediaItems
        { get { return repository.MediaItems; }}

        private MediaItem _selectedItem;
        public MediaItem SelectedItem
        {
            get {return _selectedItem; }
            set { _selectedItem = value; OnMediaChanged(SelectedItem.file); }
        }




        #region "Commands"
        private RelayCommand _cmdDirectory;

        public ICommand cmdDirectory
        {
            get
            {
                if (_cmdDirectory == null)
                    _cmdDirectory = new RelayCommand(param => this.ShowDirectory());
                return _cmdDirectory;
            }
        }

        public void ShowDirectory()
        {
            OpenFileDialog flDlg = new OpenFileDialog();
            flDlg.InitialDirectory = FolderPath;
            flDlg.Title = "Please choose a folder";
            flDlg.CheckFileExists = false;

            flDlg.FileName = "[Get Folder…]";
            flDlg.Filter = "Folders|no.files";

            if ((bool)flDlg.ShowDialog())
            {
                string path = System.IO.Path.GetDirectoryName(flDlg.FileName);
                if (path != null && path.Length > 0)
                {
                    FolderPath = path;
                    OnPropertyChanged("FolderPath");
                }
            }
        }
      

        #endregion

        #region "Media changing event"
        public void OnMediaChanged(string MediaSource)
        {
            if (MediaChanged != null)
                MediaChanged(this, new Common.MediaChangedEventArgs(MediaSource));
        }
        public event EventHandler<Common.MediaChangedEventArgs> MediaChanged;
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Anytime Fitness
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions