How to play swf file in silverlight? - c#

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

Related

Webcam video does not render again once I switch tabs

I'm using the the wpf-mediakit library to render a video stream from a usb camera for my desktop application.
Tha XAML:
<TabItem>
<Grid>
<controls:MediaUriElement x:Name="mediaUriElement" Grid.Row="1"
DeeperColor="False"
Margin="4"
Stretch="Uniform"/>
<controls:VideoCaptureElement x:Name="cameraCaptureElement" Grid.Row="1"
EnableSampleGrabbing="False"
DeeperColor="False"
Margin="4"
Stretch="Uniform"/>
</Grid>
</TabItem>
And the code-behind:
public MainWindow()
{
InitializeComponent();
cameraCaptureElement.VideoCaptureDevice = MultimediaUtil.VideoInputDevices[0];
}
The problem is, when I switch tabs and return to this tab item, the stream does not render at all. As far as I could tell, this is some Tab Virtualization problem, but I was out of ideas on how to solve this. Also, ideally, I would not want to re-initialize the stream every time as it takes a couple of seconds to do so.

VS 2013 Windows Store .. Media Element

I'm making a windows store app and i'm trying to add a sound to the button for when you click it. I have my coding done, error free, but the sound does not play.
Any help is appreciated.
XAML
<Button x:Name="Explore" HorizontalAlignment="Left" Height="163" Margin="692,461,0,0" VerticalAlignment="Top" Width="546" BorderThickness="0" Click="Explore_Click"/>
<MediaElement x:Name="suprise" Source="Assets/suprise.mp3" AutoPlay="False" Visibility="Collapsed" HorizontalAlignment="Left" Height="147" Margin="108,285,0,0" VerticalAlignment="Top" Width="533" RenderTransformOrigin="0.5,0.5"/>
xaml.cs
private void Explore_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(Explore));
suprise.Play();
}
The MediaElement needs to be in the visual tree to play and will stop when it is removed. Since Explore_Click navigates away before surprise has played, surprise isn't able to play its sound.
You have a few options:
Let surprise finish before calling Frame.Navigate. The app can handle surprise's MediaEnded event and navigate there.
Put surprise on the Explore page and play it when that page is reached
Use a global MediaElement in a page outside of the Frame containing the app's normal pages. This will let the MediaElement stay in the visual tree even as the app switches pages beneath it. This is generally needed if you want to play a consistent soundtrack during the app, but not so much for special effects. I discuss this method in more detail in my blog entry Frame of reference: keeping the music playing across pages

Play Sound Effect Windows Phone

Im trying to play a sound in my silverlight windows phone app (using SDK 7.1 Tools), when a button is pressed, but it seems that it only plays the sound when it finishes the last one.
For example, if I touch repeatly the button, it wont play the sound in the same way.
How can I solve this?
Im using media element in my xaml page
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement x:Name="kick" Source="/Sounds/Kick.wav" AutoPlay="False" Visibility="Collapsed"/>
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="165,196,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
</Grid>
and on code behind i have:
private void button1_Click(object sender, RoutedEventArgs e)
{
kick.Play();
}
OK, If someone has the same problem I found this solution.
1st: Add Reference (Microsofot.Xna.Framework) to your project
2nd: Don't forget to add this to your Page.xaml
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
3rd: Add your sounds to your project, for example, with the path: "Sounds/Sound1.wav"
4th: You can now play the sonds with the following code
PlaySound("Sounds/Sound1.wav");

Layering Image over Flash XAML

I have a flash UI, and a image. I would like to place the image OVER the flash object, but I can't seem to get it working when using Panel.Zindex.
Here is my Code
<my1:WpfFlashUI Name="mFlashUI" Margin="0,0,0,6" HorizontalAlignment="Stretch" Panel.ZIndex="2" />
<Image Name="img2" Source="http://www.donkersct.nl/wordpress/wp-content/uploads/2012/07/stackoverflow.png" Height="217" Width="363" Margin="560,199,-45,6" Panel.ZIndex="1" />
Can anyone see why this isn't working, or suggest a better way? I have tried swapping the Zvalues around.

WinRT C# Play a viddler video using MediaElement

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.

Categories