媒体没有在Windows Phone 7中的页面加载上播放 [英] media not playing on pageload in windows phone 7

查看:92
本文介绍了媒体没有在Windows Phone 7中的页面加载上播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在一个处理播放媒体的应用程序中工作。我添加了一个媒体元素并添加了要播放的文件。但是我无法在页面加载时播放它们。我在这里放置代码



xaml



Hi
I am working in a app which deals with playing media. I included a media element and added the files to be played. But i am unable to play them on page load. i am placing my code here

xaml

<MediaElement Height="Auto" HorizontalAlignment="Stretch" Margin="-12,-45,0,0" Name="mediaElement1"

 VerticalAlignment="Stretch" Width="Auto"  />





xaml.cs





xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Shell;


namespace Kids_rhymes
{
    public partial class Player : PhoneApplicationPage
    {
        MediaPlayerLauncher mediaPlayerLauncher;
        int position;

       
        public Player()
        {
            InitializeComponent();
            mediaElement1.AutoPlay= true;
            mediaPlayerLauncher = new MediaPlayerLauncher();              
        }      

        void  OnAppbarPauseClick(object sender, EventArgs args)
        {
            mediaElement1.Pause();
        }

        void OnAppbarPlayClick(object sender, EventArgs args)
        {
            string[] videos = new string[] { "abd.mp4", "hrf.mp4",};
            if (position > 0)
            {
                mediaElement1.Source = new Uri("/Videos/"+videos[position-1], UriKind.Relative);
                mediaElement1.Play();
            }
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            position = int.Parse(NavigationContext.QueryString["position"]);
            //MessageBox.Show("position " + position);

            
        }

        private void OnAppbarStopClick(object sender, EventArgs e)
        {
            mediaElement1.Stop();
        }

       
    }
}





任何人都可以告诉我为什么自动播放在这里不起作用



can any one tell me why auto play is not functioning here

推荐答案

忘了加载功能。代码在这里



xaml



forgot to put on load functionality .code goes here

xaml

<mediaelement height="Auto" horizontalalignment="Stretch" margin="-12,-45,0,0" name="mediaElement1">
 VerticalAlignment="Stretch" Width="Auto" Loaded="mediaelement1_loaded  /></mediaelement>





.cs





.cs

private void mediaElement1_Loaded(object sender, RoutedEventArgs e)
{
  //functionality
}


这篇关于媒体没有在Windows Phone 7中的页面加载上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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