Click here to Skip to main content
15,881,380 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.5K   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 System.ComponentModel; 
using System.Xml.Linq;
namespace RSSVideoPlayer.Model
{
 public class FeedItem : INotifyPropertyChanged 
    {
      
    private XElement _Feed; 
    private List<MediaItem> _MediaLinks; 
    private bool _selected; 
    
    public FeedItem(XElement element) 
    { 
        if (element == null) { 
            throw new NullReferenceException("New feed element is null"); 
        } 
        
        _Feed = element; 
        _MediaLinks = new List<MediaItem>(); 
        
        foreach (XElement m in element.Descendants()) 
        { 
            try { 
                if (m != null) { 
                    if (m.Name.LocalName == "content" | m.Name.LocalName == "enclosure") { 
                        MediaItem mediaitem = new MediaItem(m.Attribute("url").Value.ToString()); 
                        if (mediaitem.Filename.Substring(mediaitem.Filename.LastIndexOf(".")).ToLower() == ".wmv" || mediaitem.Filename.Substring(mediaitem.Filename.LastIndexOf(".")).ToLower() == ".mp4") { 
                            _MediaLinks.Add(mediaitem); 
                        }
                    }
                }
            }
            catch { throw new NullReferenceException("Error loading feed media"); } 
        }
        
    }
    
    public bool IsSelected { 
        get { return _selected; } 
        set { 
            if (_selected != value) { 
                _selected = value; 
                OnPropertyChanged("IsSelected"); 
                OnPropertyChanged("MediaItems"); 
            } 
        } 
    } 
    
    public List<MediaItem> MediaItems { 
        get { return _MediaLinks; } 
    } 
    
    public string Title { 
        get { 
            var t =  from e in _Feed.Descendants("title") select  e;
            if (t.Count() > 0) {
                return t.ElementAt<XElement>(0).Value.ToString();
            } 
            else { 
                return null; 
            } 
        } 
    } 
    
    public string Description { 
        get { 
               var t =  from e in _Feed.Descendants("title") select  e;
            if (t.Count() > 0) {
                return t.ElementAt<XElement>(0).Value.ToString();
            } 
            else { 
                return null; 
            } 
        } 
    } 
    
    public string Link { 
        get { 
                var t =  from e in _Feed.Descendants("title") select  e;
            if (t.Count() > 0) {
                return t.ElementAt<XElement>(0).Value.ToString();
            } 
            else { 
                return null; 
            } 
        } 
    }


    #region INotifyPropertyChanged Members
    private void OnPropertyChanged(string Propname)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(Propname));
    }
    public event PropertyChangedEventHandler PropertyChanged;

    #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