Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

HTML
<MediaElement Height="Auto" HorizontalAlignment="Stretch" Margin="-12,-45,0,0" Name="mediaElement1"
 VerticalAlignment="Stretch" Width="Auto"  />


xaml.cs

HTML
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
Posted
Comments
Raghavanand 21-Dec-12 6:31am    
I have solved this myself!!!

1 solution

forgot to put on load functionality .code goes here

xaml

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


.cs

HTML
private void mediaElement1_Loaded(object sender, RoutedEventArgs e)
{
  //functionality
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900