2015-04-01 67 views
-1

我想直接从MediaElement中的服务器播放视频。 (来源将是服务器) 我有服务器的URL: http://videotherapy.co/dev/vt/api/dispatcher.phpWPF:如何从MediaElement中的服务器播放视频(mp4格式)?

,并张贴以下JSON:

{"videoId":"22-1","api":"get-training-video"} 

(where 22-1 is the videoId) 

XAML代码:

<Window x:Class="MediaElementApp.MainWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="MainWindow" Height="467.91" Width="1300"> 
<Grid> 
<MediaElement x:Name="mediaElement" HorizontalAlignment="Left" Height="418" Margin="246,10,0,0" VerticalAlignment="Top" Width="1036" LoadedBehavior="Manual" UnloadedBehavior="Stop" Source="Images\Wildlife.wmv" /> 
<Button x:Name="play" HorizontalAlignment="Left" Margin="538,161,0,0" VerticalAlignment="Top" Width="100" Height="84" Click="play_Click" > 
    <Button.Background> 
     <ImageBrush ImageSource="Images/smiley.jpg"/> 
    </Button.Background> 
</Button> 

</Grid> 

C#代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace MediaElementApp 
{ 
/// <summary> 
/// Interaction logic for MainWindow.xaml 
/// </summary> 
public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

     private void play_Click(object sender, RoutedEventArgs e) 
     { 

      mediaElement.Play(); 
     } 
    } 
} 

如何做到这一点? 我想要帮助。

+0

最低要求是您至少尝试过某些东西并在遇到问题时来到这里。 – BCdotWEB 2015-04-01 10:49:30

回答

0

MediaElement接受URI为Source。像这样,它可以将视频从网络传输到客户端应用程序。

如果这在某种情况下不可行的话。您必须将视频下载到File。然后将此文件的位置传递给Source属性MediaElement

+0

我应该联系到使用Json的链接,我只是不知道如何。 – 2015-04-01 14:56:20

+0

为此,我建议您使用.Net HttpClient:https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.118).aspx。 – Bart 2015-04-01 18:57:21