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");
Related
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.
Hi i am Developing a app on universal windows 10 app platform, and when i put some Objects on the XAML window and when change the screen size it's stay how it was before so it's fit the new screen size and if i fix it it's fit the old screen size and i need the app to be universal.
my xaml code:
<Page
x:Class="App17.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App17"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Loaded="Grid_Loaded">
<Grid.Background>
<ImageBrush Stretch="UniformToFill" ImageSource="Assets/backPHONE.jpg"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="55*"/>
<RowDefinition Height="9*"/>
</Grid.RowDefinitions>
<RelativePanel>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="41,155,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="128" Width="360" Text="test 123" FontFamily="Century Gothic" FontStretch="UltraExpanded" FontStyle="Italic" FontSize="26" Tapped="textBlock_Tapped" TextAlignment="Center"/>
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="84,700,0,-666.8" VerticalAlignment="Top" Width="264" SelectionChanged="comboBox_SelectionChanged" Height="32" Grid.Row="1">
<ComboBoxItem Content="test" IsSelected="True"/>
</ComboBox>
<TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="164,675,-2.8,-665" TextWrapping="Wrap" Text="test" VerticalAlignment="Top" Height="20" Width="120" Grid.Row="1" SelectionHighlightColor="#FFF10000" FontFamily="Century Gothic" FontSize="12" FontStretch="UltraExpanded" FontStyle="Italic" Foreground="White"/>
</RelativePanel>
</Grid>
thanks
Let me introduce two possible ways to handle various screen sizes related with Universal Windows 10 Apps.
1. Adaptive Triggers - you can use them to adjut your layout to different device families - for instance you can define how your Page will look on the smartphone and while app is launched on the PC. Below I tried to add some short instructions how you can start using them.
a) When you have Visual Studio opened, please right click on the MainPage.xaml and select "Design in Blend...":
b) Go to "States" tab and select icon (marked red rectangle below) called "Add state group":
c) Now you have to add state, so click the icon next to "Visual State Group" as show below:
d) Now add two state: "Mobile" and "Desktop" as shown below:
e) Last step is to set minimum window width to detect when screen size is changed:
f) Now you are able to set minimum window width for the "Mobile" state:
Please type 320 as below (remember that these are effective pixels not physical)
Once you click "OK" Visual State for "Mobile" will be configured.
Do the same above steps but for "Desktop" state and type 1024 for minimum window width:
Now I can switch between two states and adjust the design for each of them:
(Note that currently selected state is marked with red rectange):
1. Device-Family Folders - you can specify two separate views for Pages but with one code behind. This can help if you have to craft your design specially for mobile devices and for instance fot the PCs.
a) Right click on the project and add new falder called "DeviveFamily-Mobile":
b) Add new Xaml View called the same like your previous page - in my case this is "MainPage":
c) Now you have one code behind class but two separate views that will be applied accordingly to device family:
I hope that it will help you to start.
You can also watch very good Channel9 video or visit my blog where I am trying to present a lot of helpful samples related with UWP.
you must use AdaptiveTriggers
http://www.wintellect.com/devcenter/jprosise/using-adaptivetrigger-to-build-adaptive-uis-in-windows-10
I trying to add images to my WPF windows but I'm not able to.
What I tried to do is to add Source to the Image Xaml and the image does display on the designer, but when I run the program the image is not displayed
<Image HorizontalAlignment="Left" Height="197" Margin="0,0,0,64"
VerticalAlignment="Bottom" Width="355" Source="pack://siteoforigin:,,,/Resources/Airplane1.jpg"
Grid.ColumnSpan="7"/>
Suppose that you put your image at Resources an it's build action Resource, just try to put :
<Image HorizontalAlignment="Left" Height="197" Margin="0,0,0,64"
VerticalAlignment="Bottom" Width="355" Source="/Resources/Airplane1.jpg"
Grid.ColumnSpan="7"/>
Let me know if it won't work
I am trying to add a simple map to my app.
I added map reference, added capability in WMAppManifest and this code to page:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<maps:Map x:Name="MyMap" Center="47.6097, -122.3331" ZoomLevel="10" HorizontalAlignment="Left" VerticalAlignment="Top" Loaded="Map_Loaded_1" />
</Grid>
but it show blank map. What I mean blank? a black page!
I can not get it to work. tell me what I missed!?
Try to follow this guide step by step, and see if it helps.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207045(v=vs.105).aspx
Maybe your internet connection is dead (or just not configured properly in emulator)?
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