Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

(Hybrid Smart Client) RSS Media Player

, 9 Mar 2009
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)

Share

About the Author

Paul_Wade
Software Developer (Senior) Anytime Fitness
United States United States
No Biography provided
Follow on   Twitter

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 9 Mar 2009
Article Copyright 2009 by Paul_Wade
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid