SoundClip only plays ONCE on button_Click - c#

I want my sound to play when I click a button. the sound file will play but will only play once.
I need it to play everytime i hit a button. please help.
Heres what i have so far::
XAML:
MediaElement x:Name="SoundClip" Source="Dart.mp3" AutoPlay="False" />
C#:
private void OutBull_Click(object sender, RoutedEventArgs e)
{
SoundClip.Play();
game.update_score(25);
updateGUI();
}
private void Bull_Click(object sender, RoutedEventArgs e)
{
SoundClip.Play();
game.update_score(50);
updateGUI();
}
I need all these to play the sound when i click them. Not just once in which it only does?????

If you set the MediaEnded event as below it should work.
private void SoundClip_MediaEnded(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
SoundClip.Stop();
}

SoundPlayer is only supposed to be compatible with .wav files. Have you attempted to convert your .mp3 file to a .wav file? It may be causing the SoundPlayer to stop working after the first time it plays the file due to the lack of compatibility.

So in your HTML code there should be an or something that you can set to reset
This is java but if you google onclick reset it should help.
<br>
<input type="reset" name=resetbutton value=Reset
onClick='alert("The reset button was clicked")'>
<br>
Reset the buttons at the end so the next time you click it, the methods get passed to the button again.
Should work

Related

WPF Press any button to continue to next page

Got a simple 3 page program, but would like to make a welcome screen that users have to press a button to move to the next page (and start the workflow).
Users will mostly be using a barcode scanner (captures string & hits enter), so I'm trying to avoid buttons that need to be clicked with a mouse.
The setup is basically one MainWindow with a DockPanel in it with a Frame in it.
Pages get loaded to the frame on events(the enter being hit on a textbox). Pages have Grids in them with the standard controls.
I've got the frame in the window navigating to the welcome page, but can't seem to capture a keypress.
What would set I the event on? The Window, the frame, the dockpanel, the page, the grid?
Also, is there a way to specify "any key or click" event, maybe listen for any input action?
I've tried experimenting and looking at documentation but I can't seem to get it.
I created an empty WPF app with a frame and was able to catch a keypress event. Once the app starts I focus the frame. You can do the same once your page loads or when your workflow starts over.
<Frame Loaded="FrameworkElement_OnLoaded" KeyUp="UIElement_OnKeyUp">
<Frame.Content>
<Page>
<Label Content="Hello"></Label>
</Page>
</Frame.Content>
</Frame>
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
((Frame)sender).Focus();
}
private void UIElement_OnKeyUp(object sender, KeyEventArgs e)
{
MessageBox.Show("Key pressed");
}
Add this to your designer:
this.myForm.KeyDown += new System.Windows.Forms.KeyEventHandler(this.myForm_KeyDown);
And add this to your Form's code
private void myForm_KeyDown(object sender, KeyPressEventArgs e)
{
if(KeysDown().Any())
{
currentForm.Hide();
nextForm,Show();
}
}

How to Place a Pause in a Windows Phone 8 Application

I would like to place a pause within a click event in my application. I am placing a vibration within the click event, and sometimes when a new page is navigated to, the vibration does not stop. I'm hoping that the pause will help solve this issue.
MainPage.xaml.cs
void newButton_Click(object sender, EventArgs e)
{
//Button vibration
if (Settings.EnableVibration.Value)
{
VibrateController.Default.Start(TimeSpan.FromMilliseconds(40));
//place vibration stop here
}
...
}
According to this article, the minimal duration is 0.1 seconds, while you are setting it to 0.04. Also I would try to call the VibrateController.Stop() method.
Solved with VibrationController.Default.Stop();

Calling Play() on C# ShockWave component doesn't start YouTube video playback?

I have a simple WinForms C# application that embeds a ShockWave COM component on a form. I have a Test button that when clicked, calls the Play() method on the component. When I click the button nothing happens. The YouTube player is plainly visible in the ShockWave component with a video still and the player chrome in the frame, with a big Play button on it. But it doesn't start playing.
Sample code:
private void button1_Click(object sender, EventArgs e)
{
axShockwaveFlash1.Play();
}
Does anyone know how to fix this? I'm wondering if it's because the ShockWave component might need to have "requires click to play" or some other registry/system setting cleared before the Play() method works? If that happens to be the case, then how can I do that programmatically so a new install works perfectly without putting the user through some kind of a pre-setup hassle?
With Youtube videos and AxShockwaveFlash objects the Play() method doesn't function, however, there is a nice workaround for this.
The secret is adding ?autoplay=1 to the end of the URL containing the video you wish to play.
Something like this will provide the desired effect:
private void button1_Click(object sender, EventArgs e)
{
string path = #"http://www.youtube.com/v/Q-h4ulFK2Ek?autoplay=1";
axShockwaveFlash1.Load(0, path);
}

I TRIED but InvokeMember Click is NOT working on the INPUT BUTTON, it's very different from the others

I wanted button9 to automatically click an input button in the html page using webbrowser1.
This is the code of the input button below. I got this from the page source.
<input type="image" name="phmiddle_0$ShoppingCartOrderSummary1$btnCheckout"
id="phmiddle_0_ShoppingCartOrderSummary1_btnCheckout" title="Checkout"
src="/content/images/global/buttons/checkout.gif" onclick="return
GMCR.CheckoutValidation();" style="border-width:0px;">
So this is the code I used below to click it.
private void button9_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("phmiddle_0$ShoppingCartOrderSummary1$btnCheckout").InvokeMember("Click");
}
And I also tried this
private void button9_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("phmiddle_0_ShoppingCartOrderSummary1_btnCheckout").InvokeMember("Click");
}
None of those two worked.
I also tried some other very long codes out there that contain var and htmlelement tags but none of them worked.
Please help me, what am I doing wrong here.
I clicked button9, but it does not automatically click the input button.
I FOUND THE ANSWER ALL I HAVE TO DO IS ADD THIS webBrowser1.Document.GetElementById("phmiddle_0_ShoppingCartOrderSummary1_btnChe‌​ckout").RaiseEvent("onclick");

how to execute a method BackgroundAudioPlayer fastforward?

Tell me please how to execute a method BackgroundAudioPlayer fastforward?
That is, how to do that when you long press the button, fast forward, and then release the button, the track nchinal play, in general as well as buttons work in the locked mode.
If you long press call as follows:
private void btnNext_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
BackgroundAudioPlayer.Instance.FastForward();
}
The track is scrolled to the end and pops up an error.
What is your desired behavior? You probably need some code on the MouseLeftButtonUp event to call Play to resume the playing of the current audio track.

Categories

Resources