WP8 MediaElement来源

时间:2013-08-13 07:35:12

标签: windows-phone-8 mp4 mediaelement ip-camera

我正在尝试设置媒体元素以播放来自http源的视频。来源是从ip摄像头,它只是不工作,我不知道为什么。

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();
    }
}
}

我之前从未这样做过,所以我不肯定我正在顺利进行。

1 个答案:

答案 0 :(得分:0)

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