Silverlight / WPF - Problem with media player in xaml

Asked By Daniel
04-Dec-11 12:27 PM
Hi!I am creating a video player but I it is not playing,the source of this video is on c drive.But it tells me that <<the ressource is 'file:///C:\RihannaManDown'could not be found.It should be located at 'C:\RihannaManDown' but the file is not present. See my code bellow
in xaml

<

Window x:Class="VideoPlayer.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow" Height="350" Width="525">

 

<Grid>

 

<MediaElement Height="120" HorizontalAlignment="Left" Margin="104,93,0,0" Name="mediaElement1" VerticalAlignment="Top" Width="160" Source="C:\RihannaManDown" LoadedBehavior="Manual" MediaOpened="mediaElement1_MediaOpened">

 

 

</MediaElement>

 

<Button Content="Player" Height="23" HorizontalAlignment="Left" Margin="74,258,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />

 

<Button Content="Pause" Height="23" HorizontalAlignment="Left" Margin="180,258,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />

 

<Button Content="Close" Height="23" HorizontalAlignment="Right" Margin="0,258,136,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />

 

</Grid>

</

Window>

 
code behind:

 

 

private void button1_Click(object sender, RoutedEventArgs e)

{

mediaElement1.Play();

}

 

 

private void button2_Click(object sender, RoutedEventArgs e)

{

mediaElement1.Pause();

}

 

 

private void button3_Click(object sender, RoutedEventArgs e)

{

mediaElement1.Close();

 

}

  Web Star replied to Daniel
04-Dec-11 01:22 PM
you can use this link to player in xaml page
http://www.codeproject.com/KB/WPF/WPF_Media_Player.aspx
  Anoop S replied to Daniel
04-Dec-11 11:13 PM
In source property you need to specify file type whether its wmv or mp4 like that

VerticalAlignment="Top" Width="160" Source="C:\RihannaManDown.wmv" LoadedBehavior="Manual"
 
  R B replied to Daniel
05-Dec-11 01:54 AM

Hello

 

Is the sound file in or outside of the xap?  Try a local test of the sound file in a new project. 

Sound file in XAP:
XAML: 

<MediaElement x:Name="media" Source="Kalimba.mp3" />

 

Sound file not in XAP (relative path to XAP):
XAML: 

<MediaElement x:Name="media" />

 

C#: 

media.Source = new Uri("Kalimba.mp3", UriKind.Relative);

 

Sound file not in XAP (Webclient approach):

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();

        WebClient client = new WebClient();
        client.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
        client.OpenReadAsync(new Uri("Kalimba.mp3", UriKind.Relative));
    }

    void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null)
            media.SetSource(e.Result);
    }
}

 

Hope this helpful

  R B replied to Daniel
05-Dec-11 02:00 AM

Hello

 

The local file won't work in a normal Silverlight application because of Silverlights "sanboxed" security model.

Running a normal Silverlight application in your browser, you can't access local resources like you can if you were running an installed winforms/WPF application.

Have a look at this video tutorial http://www.silverlight.net/learn/videos/all/local-file-access/, if you want to learn more about accessing local files using Silverlight.

 

I created a sample app and pointed it at your mp3 file and it' wouldn't work, however a quick search for sample mp3s, lead me to another freely available (first hit). Using the code/url below, it works ok.

 

myMediaelement.Source = new Uri("http://www.robtowns.com/music/blind_willie.mp3", UriKind.Absolute);
 
 
In regards to the loading, it will start downloading the file when it hits the code that sets the source of the mediaelement. 
 
So if you set the source for the media element in your constructor or in your loaded event, it will automatically start downloading in the background.
 
Then you just call myMediaelement.Play(); on the button click event.

 

Hope this helpful

  Vickey F replied to Web Star
05-Dec-11 06:01 AM
Try like this-


Adding media to an application is as simple as adding a MediaElement control to the user interface (UI) of the application and providing a Uri to the media you wish to include. All media types supported by Microsoft Windows Media Player 10 are supported in Windows Presentation Foundation (WPF). The following example shows a simple usage of the MediaElement in Extensible Application Markup Language (XAML).


<!-- This page shows a simple usage of MediaElement -->
<Page x:Class="MediaElementExample.SimpleUsage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="SimpleUsage" > <StackPanel Margin="20"> <MediaElement Source="media/numbers-aud.wmv" /> </StackPanel> </Page>

Follow this link for more help-


http://msdn.microsoft.com/en-us/library/aa970915.aspx
Create New Account
help
culture) { var rawImageData = value as byte []; if (rawImageData = = null ) return null ; var bitmapImage = new System.Windows.Media.Imaging.BitmapImage(); using (var stream = new MemoryStream(rawImageData)) { bitmapImage.BeginInit(); bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat The next step is to call this handler from our Silverlight application. C# using System.Windows.Media.Imaging; public partial class Page : UserControl { public Page() { InitializeComponent(); } private void btnImage_Click(object sender the WebClient class to download images You need to import the System.Net and System.Windows.Media.Imaging namespaces. Also we will be using event-handlers while using the WebClient, since Convert.ToInt32(txtEmpID.Text).ToString(); txtProgress.Text = String.Empty; wc = new WebClient(); wc.OpenReadCompleted + = new OpenReadCompletedEventHandler(wc_OpenReadCompleted); wc.OpenReadAsync(new Uri(imgUri, UriKind.Absolute)); txtProgress.Text = "Fetching Image. . ."; / / img1.Source = new BitmapImage(new Uri(s, UriKind.Absolute)); } void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { if (e.Error = = null) { try { BitmapImage image = new BitmapImage(); image.SetSource(e.Result); img1
Doubt in webClient class in silver light. . .!!! Hii, , I am developing an app in windows phone 7, which will download the Video files from my server. I did it by where it is storing the stream Data. I want to locate it locally in my windows phone.And how to access the file Explorer in windows phone 7?? And is it Possible to download the video stream data chunk by chunk wc.OpenReadAsync(new Uri("http: / / www.test.com / Wildlife.wmv", UriKind.RelativeOrAbsolute)); wc.OpenReadCompleted+ = new OpenReadCompletedEventHandler(ReadCompleted); wc.DownloadProgressChanged + = new DownloadProgressChangedEventHandler(ProgressBarSataeChanged); } void ProgressBarSataeChanged(object s, DownloadProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; textBlock1.Text = "Downloaded " + progressBar1.Value.ToString() + "%"; } void ReadCompleted(object s, OpenReadCompletedEventArgs e) { / / Here I want some code to Store it Locally in device. } Check intellisense for
up Office I'm not at all sure what to do here. When I run windows update, the junk mail filter KB936677 for Outlook 2003 keeps on coming up time after bytes) OUTLFLTR.DLL 1.4.3504.0 300 KB (307, 440 bytes) I'm running Windows XP / sp2 and office 2003 / sp3 and searching around the web, there's other with IE7, I choose not to install yet) have installed without a hitch, that's both Windows and Office. Even this (KB936677) update appears to have installed, giving the following message: 'The 2007 23:43:50 Build type: SHIP UNICODE 3.01.4000.4039 Calling process: C: \ WINDOWS \ system32 \ msiexec.exe = = = MSI (c) (2C:F4) [23:43:50:122]: Resetting cached policy values End dialog not enabled MSI (s) (18:A4) [23:43:51:413]: Original package = = > C: \ WINDOWS \ Installer \ 2ff58.msi MSI (s) (18:A4) [23:43:51:423]: Package we're running from = = > C: \ WINDOWS \ Installer \ 2ff58.msi MSI (s) (18:A4) [23:43:51:554]: APPCOMPAT: looking for appcompat copy from system32 MSI (s) (18:A4) [23:43:51:634]: Opening existing patch 'C: \ WINDOWS \ Installer \ 38c3c4.msp'. MSI (s) (18:A4) [23:43:53:767]: Opening existing patch 'C: \ WINDOWS \ Installer \ 461cb63.msp'. MSI (s) (18:A4) [23:43:54:528]: Opening existing patch 'C
Windows installer 3.1 & IE7 fails to install Windows 7 3 weeks ago I upgraded my motherboard, processor, RAM & display card. Since I can't clean install a new windows XP cause my old system has all needed programs & settings to my needs (very hard I used to option of repair install, inserted the XP CD that gave me "upgrading windows", & all went OK, new drivers installed, removed old ones. Funny thing is my IE7 is goes till the point where registry editing starts & stops installation & rolls back changes to IE6 & windows restarts. . Same when I try to update Windows installer to 3.1, it stops installation at the point or registry changing & rolls back account, how come? Why both installation stops at the registery editing point? Any help? thanks Windows Update Discussions DontRemoveOnUninstall.System32.DirId (1) ProductInstall.GlobalRegistryChanges.Install (1) Windows XP (1) Internet Explorer 7 (1) Windows Installer (1) Windows Update (1) IsRebootRequiredForFileQueue (1) ProcessesToRunAfterReboot