I am trying to play a Viddler video in my application but i cant get it to work.
Here is my simple code:
XAML:
< MediaElement VerticalAlignment="Center" Visibility="Visible"
HorizontalAlignment="Center"
Name="myMediaElement" Height="350"
Width="640" />
And my c#:
myMediaElement = new MediaElement();
Uri url = new Uri("http://www.viddler.com/embed/5b17d44f/");
myMediaElement.Source = url;
myMediaElement.Play();
Any help would be great! When i arrive on the page, nothing happens, the application does not break it just does nothing....
Edit:
In the end I have just decided to call the http://www.viddler.com/embed/5b17d44f/ url into a Webview, its not the best idea but it works.
Dont create a new MediaElemet. You already have one created (XAML).
Set AutoPlay="True" in your XAML
Edit: Play works only if the media is already loaded.
Related
The task should be simple. I have an Image with a "Tapped" even handler, and i want to play a wav file when it is clicked.
<Image x:Name="Snd_abort_1" Width="100" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Source="Assets/Tiles/A/abort_1.png" Tapped="Snd_abort_1_Tapped"></Image>
private void Snd_abort_1_Tapped(object sender, TappedRoutedEventArgs e)
{
MediaElement myMediaElement = new MediaElement();
myMediaElement.AutoPlay = false;
myMediaElement.Source = new Uri("ms-appx:///Assets/Sounds/DukeNukem/abort.wav");
myMediaElement.Play();
}
For some particular reason this does not work.
I tried to debug the click and that fires but no error, no sound.
I have tried both in emulator and on my Lumia 930 device.
What am i missing out?
You don't need to prefix your files with ms-appx:, just do
myMediaElement.Source = new Uri("Assets/Sounds/DukeNukem/abort.wav", UriKind.Relative);
myMediaElement.Play();
Unfortunately, though it is correct. This code-behind approach will still not work. Because the myMediaElement is not part of the VisualTree (because you made it dynamically).
To fix this, just add it to the root Grid/Panel
myMediaElement.Source = new Uri("Assets/Sounds/DukeNukem/abort.wav", UriKind.Relative);
this.ContentPanel.Children.Add(myMediaElement);
myMediaElement.Play();
Now it should play nicely with everything.
A friend and I have tried to get the video player on Windows Phone 8.1 to play a m3u8 stream, but we've been unavailable to succeed.
What we've tried:
We've tried with playerframework.codeplex.com (Microsoft Player Framework), but it was unable to load the file.
We also tried with Windows Phone Streaming Media (https://phonesm.codeplex.com/), but we were unable to as much as use this one as we couldn't make sense of their documentation on how we actually had to load the file?
Is there anybody who have worked with this kind of files before? I understand that m3u8 is not natively supported by Windows Phone 8.1
Download the player framework, consume the following DLL's:
Add the player to your xaml:
xmlns:mmppf="using:Microsoft.PlayerFramework"
xmlns:smmedia="using:SM.Media.MediaPlayer"
<mmppf:MediaPlayer IsFullScreenVisible="True" IsFullScreenEnabled="True" IsFullScreen="False" CurrentStateChanged="mPlayer_CurrentStateChanged" x:Name="mPlayer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsFastForwardEnabled="False" IsInfoEnabled="False" IsLive="True" IsMoreEnabled="False" IsRewindEnabled="False" IsRightTapEnabled="False" IsScrubbingEnabled="False" IsSeekEnabled="False" IsSkipBackEnabled="False" IsSkipAheadEnabled="False" IsReplayEnabled="False" IsTimelineVisible="False" IsTimeElapsedVisible="False" IsTimeRemainingVisible="False" RequestedTheme="Dark">
<mmppf:MediaPlayer.Plugins>
<smmedia:StreamingMediaPlugin />
</mmppf:MediaPlayer.Plugins>
</mmppf:MediaPlayer>
Then set your stream VIA code - or XAML if the URL never changes.
#Mahesh Vemuri asked what if he has error that says StreamingMediaPlugin is not available or not found in namespace, here is my work around:
XAML:
xmlns:PlayerFramework="using:Microsoft.PlayerFramework"
<PlayerFramework:MediaPlayer Name="player"
Source="http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"
AudioCategory="BackgroundCapableMedia"
IsAudioSelectionVisible="True">
<PlayerFramework:MediaPlayer.Plugins>
</PlayerFramework:MediaPlayer.Plugins>
</PlayerFramework:MediaPlayer>
And in your .xaml.cs file you simply do this:
SM.Media.MediaPlayer.StreamingMediaPlugin asd = new SM.Media.MediaPlayer.StreamingMediaPlugin();
player.Plugins.Add(asd);
player.Source = new Uri("address-to-m3u8");
It worked for me since "default" way didn't. Hope it helps someone else, too.
you can add them from xaml or cs. First add reference.
XAML
xmlns:local="clr-namespace:Microsoft.PlayerFramework;assembly=Microsoft.PlayerFramework"
xmlns:smmedia="clr-namespace:SM.Media.MediaPlayer;assembly=SM.Media.MediaPlayer.WP8"
<local:MediaPlayer Name="player"
HorizontalContentAlignment="Stretch"
AutoPlay="True"
Volume="0.7"
Source="http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"
IsPlayPauseVisible="True">
<local:MediaPlayer.Plugins>
<smmedia:StreamingMediaPlugin />
</local:MediaPlayer.Plugins>
</local:MediaPlayer>
XAML & CS
xmlns:local="clr-namespace:Microsoft.PlayerFramework;assembly=Microsoft.PlayerFramework"
<local:MediaPlayer Name="player"
HorizontalContentAlignment="Stretch"
AutoPlay="True"
Volume="0.7"
IsPlayPauseVisible="True">
</local:MediaPlayer>
SM.Media.MediaPlayer.StreamingMediaPlugin asd = new SM.Media.MediaPlayer.StreamingMediaPlugin();
player.Plugins.Add(asd);
player.Source = new Uri("http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8");
The audio is playing well when giving the local audio file as the source for the MediaElement.
<MediaElement Grid.Row="1" Stretch="Uniform" Name="Player" Margin="0,93,0,0" Source="Assets/test.mp3" />
But it is not working when try to play the remote audio file.
In the MainPage.xaml.cs
Player.Source = new Uri("http://fileraja.com/tamil/A/Alaipayuthey/Pachchai_Nirame-VmusiQ.Com.mp3", UriKind.RelativeOrAbsolute);
Please give me a solution. How to set the source for the MediaElement for a remote audio?
I Used to add MediaElement to for ex. MainPage.xaml as:
<MediaElement Name="MediaContent" AutoPlay="True"/>
and in MainPage.cs Constructor or OnNavigateTo i Use:
MediaContent.Source = new Uri("Ur Uri String Here", UriKind.Absolute);
if you don't want to auto play it in page loading just set AutoPlay to False, and play it on button click -for ex.- or any other event like that:
MediaContent.Play();
if it doesn't work try to use:
MediaFailed, MediaOpened, MediaEnded ,CurrentStateChanged .. events to keep track on why it doesn't work.
I have a metro app and I have added an existing file into a folder inside solution explorer. I have read the resources docs on msdn but can't get it figured out.
My sound file is located in Assets\SFX\Standard.wav, so how would I locate and play this file using MediaElement in my app from codebehind?
I am not sure why you would want to use MediaElement, perhaps you could try SoundPlayer?
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "\Assets\SFX\Standard.wav";
player.Play();
Edit with MediaElement:
<MediaElement Name="TehSoundz" IsLooping="False" AutoPlay="False" Height="0" Width="0" Source="\Assets\SFX\Standard.wav" />
Codebehind:
TehSoundz.Play();
TehSoundz.Stop();
I am tring to play a .swf in silverlight5 page.I am using the ListBox control or Image Control
Or Any Idea To Play swf File in Silvarlight
<Image Grid.Row="0" Name="bottom_video" Height="80" Source="{Binding VodeoUrl,Mode=OneWay}" Margin="0,20,0,0" />
You might be able use the the Flash ActiveX control that is automatically installed with the flash player itself on every windows machine but if it works it'd still comes with a lot of limitations as stated here another problem will be the "Airspace" problem.
Another way is to convert the SWF to XAML using this. But I found quite a lot of swf files that couldn't be converted. Especially if there is a lot of ActionScript or dynamic loading of content involved.
You can see in the code below how to use Iframe on Silverlight:
<Grid x:Name="LayoutRoot">
<HyperlinkButton Content="HyperlinkButton" Height="23" HorizontalAlignment="Left" Margin="44,20,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="100" TargetName="" Click="hyperlinkButton1_Click" />
</Grid>
code behind:
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e) {
HtmlDocument _document = HtmlPage.Document;
HtmlElement iframe = _document.CreateElement("IFRAME");
iframe.SetAttribute("src", "http://localhost:52878/TestForm.aspx");
iframe.SetStyleAttribute("position", "absolute");
iframe.SetStyleAttribute("top", "100px");
iframe.SetStyleAttribute("left", "200px");
HtmlElement body = (HtmlElement)_document.GetElementsByTagName("BODY")[0];
body.AppendChild(iframe);
HtmlDocument _document = HtmlPage.Document;
HtmlElement iframe = _document.CreateElement("IFRAME");
iframe.SetAttribute("src", "http://localhost:52878/TestForm.aspx");
iframe.SetStyleAttribute("position", "absolute");
iframe.SetStyleAttribute("top", "100px");
iframe.SetStyleAttribute("left", "200px");
HtmlElement body = (HtmlElement)_document.GetElementsByTagName("BODY")[0];
body.AppendChild(iframe);
}
I've got the answer for how to play an swf file in Silverlight 5
<WebBrowser Grid.Row="1" VerticalAlignment="Top" Source="{Binding VodeoUrl,Mode=OneWay}" Height="280" Width="280"/>
This is impossible. Silverlight does not play swf files. If it is just a video file without any interaction, you might be able to convert the video to something that Silverlight can play. Here is some information about the supported formats:
http://msdn.microsoft.com/en-us/library/cc189080%28v=vs.95%29.aspx