首页 \ 问答 \ WPF:为什么MediaElement不播放?(WPF: Why MediaElement does not play?)

WPF:为什么MediaElement不播放?(WPF: Why MediaElement does not play?)

我想要显示视频。 我想要点击按钮播放视频。 视频无法播放。 我将视频放入项目中。

我希望视频源是YouTube。

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

我想帮忙。


I want to display video. I want the video will play with a click on button. The video does not play. I put the video into the project.

I want that the video source will be YouTube.

My XAML code is:

<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# code:

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

I would like for help.


原文:https://stackoverflow.com/questions/29376929
更新时间:2023-08-12 15:08

最满意答案

我认为双链表正是你想要的(假设你不想要一个优先级队列):

  1. 方便快捷地为两端添加元素
  2. 从任何地方轻松快速地去除元素

你可以使用std::list容器,但是(对于你的情况),如果你只有一个指向元素的指针(或引用)(包装在STL的列表元素中),那么很难从列表中移除一个元素,但是你没有迭代器。 如果使用迭代器(例如存储它们)不是一个选项 - 那么实现一个双链表(即使使用元素计数器)应该很容易。 如果你实现你自己的列表 - 你可以直接操作指向元素的指针(每个元素都包含指向它的两个邻居的指针)。 如果你不想使用Boost或STL,这可能是最好的选择(也是最简单的),并且你可以控制一切(你甚至可以编写你自己的块分配器来加快列表元素的速度)。


I think that double-link list is exactly what you want (assuming you do not want a priority queue):

  1. Easy and fast adding elements to both ends
  2. Easy and fast removal of elements from anywhere

You can use std::list container, but (in your case) it is difficult to remove an element from the middle of the list if you only have a pointer (or reference) to the element (wrapped in STL's list element), but you do not have an iterator. If using iterators (e.g. storing them) is not an option - then implementing a double linked list (even with element counter) should be pretty easy. If you implement your own list - you can directly operate on pointers to elements (each of them contains pointers to both of its neighbours). If you do not want to use Boost or STL this is probably the best option (and the simplest), and you have control of everything (you can even write your own block allocator for list elements to speed up things).

相关问答

更多
  • 你可以使用std::set 。 它对插入其中的元素进行排序。 要检查元素是否已存在,可以使用set::find 。 要检索前导元素,可以使用set::begin iterator,最后一个元素可以使用set::rbegin 。 要删除这些元素,可以使用set::erase方法。 You can use std::set. It sorts the elements inserted into it. To check whether an element already exists you can use ...
  • 考虑由哈希表H和数组A组成的数据结构。哈希表键是数据结构中的元素,值是它们在数组中的位置。 insert(value):将值附加到数组,并将其作为A中的索引。Set H [value] = i。 remove(value):我们将使用A中的最后一个元素替换包含A中的值的单元格。令d是索引m处的数组A中的最后一个元素。 让我是H [value],数组中的索引值要被删除。 设置A [i] = d,H [d] = i,将数组的大小减小1,并从H. contains(value):return H.contains ...
  • 不要重新发明轮子,使用ConcurrentLinkedQueue而不是LinkedList然后使用iterator()来构建本机线程安全的快照。 您的方法getSnapshot将是简单的 public List getSnapshot() { return new ArrayList<>(queue); } Don't reinvent the wheel, use ConcurrentLinkedQueue instead of LinkedList then use the iterat ...
  • 使用循环缓冲区 。 当空间不足时,尺寸加倍。 这将在开始/结束时执行插入/删除以及在每个操作的O(1)时间内进行随机访问(摊销)。 在C ++中,std :: deque可以在开始/结束时进行插入/删除,也可以在O(1)中进行随机访问。 Use a circular buffer. Double the size when you run out of space. This will perform insert/delete at start/end as well as random access i ...
  • 我认为双链表正是你想要的(假设你不想要一个优先级队列): 方便快捷地为两端添加元素 从任何地方轻松快速地去除元素 你可以使用std::list容器,但是(对于你的情况),如果你只有一个指向元素的指针(或引用)(包装在STL的列表元素中),那么很难从列表中移除一个元素,但是你没有迭代器。 如果使用迭代器(例如存储它们)不是一个选项 - 那么实现一个双链表(即使使用元素计数器)应该很容易。 如果你实现你自己的列表 - 你可以直接操作指向元素的指针(每个元素都包含指向它的两个邻居的指针)。 如果你不想使用Boos ...
  • 这听起来像一个平衡的二叉树,其插入操作具有唯一性限制,并实现OS-SELECT操作(参见: 算法简介 ,第3版第14章),用于检索给定其排名的元素(“索引”)在O(lg n)中。 建议的数据结构和增强操作将允许您: 保持唯一值,在O(lg n)中执行插入操作 使用O(lg n)搜索操作保持元素排序 在O(lg n)中给出其等级的元素 That sounds like a balanced binary tree, with a restriction of uniqueness in its insert ...
  • 实际上,您不必担心重复信息:dict的键和对象的.key属性只是对完全相同对象的两个引用。 唯一真正的问题是“如果.key被重新分配会怎么样”。 那么,显然你必须使用一个属性来更新所有相关的dicts以及实例的属性; 所以每个对象必须知道可以注册的所有序列。 理想情况下,人们可能希望为此目的使用弱引用,以避免循环依赖,但是,唉,你不能将一个weakref.ref (或代理)带到一个字典。 所以,我在这里使用普通引用(替代方法不是使用dict实例,而是使用一些特殊的子类 - 不方便)。 def enregis ...
  • 根据您对要实现的树结构所做的描述,最好创建一个新的数据结构来模拟树。 特别是如果你已经在跟踪节点之间的指针。 如果我理解您的语句,树中的每个节点都将包含子节点指针的向量。 当您需要拆分节点时,您可以创建新节点,每个节点都接收子节点向量的一段,并且新创建的节点将插入父节点的节点向量中。 例如: N1->N2->(n3,n4,n5,n6,n7,n8)将N2分成两个节点: N1->(N2_1, N2_2) , N2_1->(n3,n4,n5)和N2_2->(n6,n7,n8) (对不起,我不知道如何轻松画树... ...
  • 二进制堆是优先级队列抽象数据结构的具体实现。 它很受欢迎,因为它易于实现,内存效率高且速度相当快:O(log n)插入和O(log n)删除根(最小堆中最小,最大堆中最大)元素。 大多数实现还提供了一种peek方法,允许查看根元素而不删除它。 二进制堆没有做任何其他事情。 与您的观察相反,在二进制堆中查找特定项目需要顺序扫描。 虽然节点是有序的(未排序),但顺序不适合搜索。 二进制堆的典型实现是在数组中。 由于形状属性 (结构可以被视为完美(或完整)二叉树),这意味着父和子之间的关系是隐式表示的。 这些项目 ...
  • 我认为你的案例最好的数据结构是一个环形缓冲区/循环缓冲区 。 环形缓冲区在恒定时间内执行所有三个操作。 这里可以找到一个实现, 这里有很多其他的实现 编辑: ringbuffers的问题是你应该在开始时知道最坏情况下该缓冲区中有多少元素。 但是也存在动态环缓冲区。 I think the best datastructure for your case is a ringbuffer/circular buffer. The ringbuffer performs all three operations ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。