视频流mvc2 c# [英] Video streaming mvc2 c#

查看:97
本文介绍了视频流mvc2 c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在创建一个允许用户流式传输视频的公共网站,我不打算进入网站逻辑我会坚持点。我希望能够从服务器中提取视频并在我的网站上播放它们,我已经去试图获得这个,无数的教程,但不知何故它们不起作用



有没有办法在我的mvc2 c#web应用程序中使用我使用silverlight创建的播放器?

还是有更好的方法吗?



任何帮助将不胜感激。



MainPage.xaml



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

<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




MainPage.xaml.cs

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";
        }
    }
}







以上是Silverlight我只用于播放视频的应用程序我可以在MVC2 Web应用程序中使用它吗?




Above Is a Silverlight application that I only use to playback video Can I use this in an MVC2 web application?

推荐答案

很难在不看代码的情况下回答。是的,您可以流式传输视频。 MVC2只是你的一个表示层,它有点无关紧要,你只需要发出HTML来播放你的视频,而MVC2就是你正在做的事情。无论您的网站是PHP,经典ASP还是其他什么,HTML都是一样的。唯一的缺点是,你的视频是如何存储的,如果它们存在于数据库中,你需要编写HTTP处理程序来传输它们,但这是广泛记录并且易于操作。我打算把它作为评论,但现在老实说,这是任何人都可以给你的唯一答案。如果您发布更多详细信息,我将很乐意尝试提供更多帮助。
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.


这篇关于视频流mvc2 c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆