0

我正在尝试设置一个媒体元素来播放来自 http 源的视频。来源来自网络摄像机,它只是不工作,我不知道为什么。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using FullCam.Resources;

namespace FullCam
{
    public partial class MainPage : PhoneApplicationPage
{

    // Constructor
    public MainPage()
    {
        string sourceURL = "http://xxx.xxx.xxx.xxx/display_pic.cgi?cam=1&id=807933130&res=hi&format=mp4&txmode=binary";
        InitializeComponent();

       // Sample code to localize the ApplicationBar
        BuildLocalizedApplicationBar();
        iniCamBox(camBox_1, sourceURL, "user", "password");
    }

    private void BuildLocalizedApplicationBar()
     {
        // Set the page's ApplicationBar to a new instance of ApplicationBar.
        ApplicationBar = new ApplicationBar();

        // Create a new button and set the text value to the localized string from AppResources.
        ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        appBarButton.Text = AppResources.AppBarButtonText;
       ApplicationBar.Buttons.Add(appBarButton);

       // Create a new menu item with the localized string from AppResources.
       ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        ApplicationBar.MenuItems.Add(appBarMenuItem);
    }

    private void iniCamBox(MediaElement box, string source, string user, string pass)
    {
        Uri mainSource = new Uri(source);

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(mainSource);
        req.Credentials = new NetworkCredential(user, pass);

        box.Source = mainSource;
        box.Play();
    }
}
}

我以前从未这样做过,所以我不确定我是否正确进行。

4

1 回答 1

0

我的建议是看看这个教程MSDN Media Element

于 2013-08-13T07:42:23.027 回答