Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am creating a public site that enable users to stream videos, I'm not gonna go into the site logic I'll stick to the point. I want to be able to pull videos from a server and play them on my site, I've gone 360 trying to get this, countless tutorials but somehow they don't work

Is there a way to use a player I created using silverlight in my mvc2 c# web application?
or is there a better approach in doing this?

Any Assistance will be appreciated.

MainPage.xaml

HTML
<UserControl x:Class="SimplePlayer.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:SSME="clr-namespace:Microsoft.Web.Media.SmoothStreaming;assembly=Microsoft.Web.Media.SmoothStreaming"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="0.95*"></RowDefinition>
            <RowDefinition Height="0.05*"></RowDefinition>
        </Grid.RowDefinitions>
       
        <SSME:SmoothStreamingMediaElement AutoPlay="True" x:Name="SmoothPlayer" SmoothStreamingSource="http://streams.smooth.vertigo.com/elephantsdream/Elephants_Dream_1024-h264-st-aac.ism/manifest" Grid.Row="0" />
        
        <StackPanel Orientation="Horizontal" Grid.Row="1">
            <TextBlock x:Name="Volume" VerticalAlignment="Center" Text="Volume" Width="50" />
            <Slider x:Name="VolumeBar" Width="60" Value="{Binding Path=Volume, ElementName=SmoothPlayer, Mode=TwoWay}" />
            <Button x:Name="PlayButton" Width="50" Click="PlayButton_Click" Loaded="PlayButton_Loaded"/>
            <Button x:Name="StopButton" Content="Stop" Width="50" Click="StopButton_Click" />
        </StackPanel>
    </Grid>
</UserControl>



MainPage.xaml.cs
C#
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 Microsoft.Web.Media.SmoothStreaming;

namespace SimplePlayer
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
        private void PlayButton_Loaded(object sender, RoutedEventArgs e)
        {
            //We need to prepopulate the value of Play/Pause button content, we need to check AutoPlay
            switch (SmoothPlayer.AutoPlay)
            {
                case false:
                    PlayButton.Content = "Play";
                    break;
                case true:
                    PlayButton.Content = "Pause";
                    break;
            }
        }

        private void PlayButton_Click(object sender, RoutedEventArgs e)
        {
            //Monitor the state of the content to determine the right action to take on this button being clicked
            //and then change the text to reflect the next action
            switch (SmoothPlayer.CurrentState)
            {
                case SmoothStreamingMediaElementState.Playing:
                    SmoothPlayer.Pause();
                    PlayButton.Content = "Play";
                    break;
                case SmoothStreamingMediaElementState.Stopped:
                case SmoothStreamingMediaElementState.Paused:
                    SmoothPlayer.Play();
                    PlayButton.Content = "Pause";
                    break;
            }
        }

        private void StopButton_Click(object sender, RoutedEventArgs e)
        {
            //This should simply stop the playback
            SmoothPlayer.Stop();
            //We should also reflect the chang on the play button
            PlayButton.Content = "Play";
        }
    }
}



Above Is a Silverlight application that I only use to playback video Can I use this in an MVC2 web application?
Posted
Updated 15-Jun-13 2:58am
v2

1 solution

Hard to answer without seeing code. Yes, you can stream videos. MVC2 is just a presentation layer to you, it's kind of irrelevant, you just need to emit HTML to play your videos and MVC2 happens to be how you're doing it. The HTML is the same, regardless of if your site was PHP, classic ASP, or whatever. The only wrinkle is, how your videos are stored, if they live in the DB, you need to write HTTP handlers to stream them, but this is widely documented and easy to do. I contemplated making this a comment, but right now it is honestly the only possible answer anyone can give you. If you post more details, I'll be happy to try to help more.
 
Share this answer
 
Comments
mlingo209 15-Jun-13 9:02am    
I've added the code I used in the silverlight application for video playback, can I use this code or the whole app in my mvc2 c# application?
Christian Graus 15-Jun-13 19:23pm    
there is no need to use silverlight, why do you need to add that your dependencies ? However, there's no reason you can't add silverlight, it just means your MVC2 app will just contain the HTML to run your silverlight application for that portion of your site.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900