Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / XAML

Silverlight 4: Creating an Application to Play Offline Media

Rate me:
Please Sign up or sign in to vote.
4.92/5 (14 votes)
11 Mar 2010CPOL2 min read 34.5K   769   18  
Discovering the features of Silverlight 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

namespace OfflineVideos.UI
{
    public partial class MainAppView : UserControl
    {
        public MainAppView()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainAppView_Loaded);
        }

        void MainAppView_Loaded(object sender, RoutedEventArgs e)
        {
            Button_Click(null, null);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();
            ofd.Filter = "Media Files |*.wmv;*.wma;*.mp3";
            ofd.Multiselect = false;
            if((bool)ofd.ShowDialog())
            {
                if(File.Exists(ofd.File.FullName))
                {
                    LoadMedia(ofd.File.OpenRead());
                }
            }
        }

        void LoadMedia(Stream file)
        {
            player.SetSource(file);
        }
    }
}

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
Architect
Brazil Brazil
Senior Software Architect from Brazil.

Comments and Discussions