MediaElement WP8中没有媒体显示 [英] No Media Display In MediaElement WP8

查看:86
本文介绍了MediaElement WP8中没有媒体显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我正在尝试创建一个简单的IP Cam查看器,但是我遇到了一些问题。  如果我在浏览器中转到该视频显示的URL,但是当我尝试将其设置为图像框或媒体元素的源时,它不会显示。您可以在下面查看我的完整代码
,当然敏感信息已经更改。

Basically I am attempting to create a simple IP Cam viewer, but am having a few issues.  If I go to the URL in a browser the video displays, but when I try to set it as a source for either an image box or a media element it does not display. You can view my full code below, of course sensitive information has been changed.

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

任何帮助或提示都将不胜感激。这是我的第一个深度应用程序,我主要开发游戏,所以我不习惯使用C#中的控件。

Any help, or tips would be appreciated. This is my first in depth app, I have mainly developed games, so I am not used to using the controls in C#.

推荐答案

嗨Greg,

在我看来,你的相机需要凭据。 您正尝试使用HttpWebRequest传递那些但仅适用于该连接,而不是媒体元素。 如果您附加了Fiddler,您可能会在媒体元素发出的请求中看到401未经授权的
,这将失败。

It looks to me like your camera needs credentials.  You are trying to pass those using an HttpWebRequest but that would be for that connection only and not for the Media Element.  If you attached Fiddler you would probably see a 401 unauthorized on the request the Media Element is making and that would fail.

如果您暂时删除了凭据的必要性会发生什么IP cam?

What happens if you temporarily remove the necessity for credentials on the IP cam?

Jeff


这篇关于MediaElement WP8中没有媒体显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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