I'm trying to auto repeat a MediaElement. I did that using the following code:
<MediaElement Name="MainMedia" MediaEnded="MainMedia_MediaEnded_1" />
private void MainMedia_MediaEnded_1(object sender, RoutedEventArgs e)
{
MainMedia.Position = TimeSpan.FromSeconds(0);
MainMedia.Play();
}
But I was wondering if there is any better solution.
There is a property called IsLooping. If you set that to true it will auto repeat the media.
Related
When I set player not in fullscreen (player.IsFullWindows = false), event work normally but when change player to full screen all manipulation event not work. Anyone have solution?
<MediaElement Name="player"
Margin="10,5" ManipulationCompleted="player_ManipulationCompleted"
ManipulationDelta="Grid_ManipulationDelta"
ManipulationMode="TranslateX"
>
I can reproduce this scenario by enabling both the IsFullWindow="True" and the AreTransportControlsEnabled="True". I think it makes sense, because when we are in the Full Window mode, it will go to the new layer named FullWindowMediaRoot instead of the MediaElement. Inside the FullWindowMediaRoot, it is the MediaTransportControls. You can see that clearly by using the Live Visual Tree as following:
So when we are in the Full Window mode, we need to handle the manipulation event of the TransportControls instead of the manipulation event of the MediaElement as following:
public MainPage()
{
this.InitializeComponent();
player.TransportControls.ManipulationMode = ManipulationModes.TranslateX;
player.TransportControls.ManipulationDelta += TransportControls_ManipulationDelta;
player.TransportControls.ManipulationCompleted += TransportControls_ManipulationCompleted;
}
private void TransportControls_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
}
private void TransportControls_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
}
Thanks.
I'm trying to invoke messagedialog from setting flyout for my Windows 8 Metro app but it's causing the message dialog to flicker. Below is the code.
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested+=settings_CommandsRequested;
}
private void Settings_CommandsRequested(SettingsPane sender, SetttingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand cmd = new SettingsCommand("test","test1232",new UICommandInvokedHandler(CreateDialog));
args.Request.ApplicationCommands.Add(cmd);
}
private void CreateDialog(IUICommand command)
{
if (ReferenceEquals(command.Id, "cmd"))
{
MessageDialog md = new MessageDialog("Hi");
md.ShowAsync();
}
}
I've contacted official microsoft dev-support and their response was:
"MessageDialog is not recommended within the SettingsFlyout".
So in case you want to implement something simillar to support user's decision from the SettingsPane, you should either:
1) Enable toggling feature in the Flyout.
2) Desiging the SettingsFlyout so it lets the user make decision (for example in Logout cases, add Yes/no buttons inside the settingsFlyout) - Thats the option I chose.
How i can delete the key which presente "Enter"?? I want the programme show "Plase enter Espace or Tab" when the user tape Enter and then delete this Enter Key. Thank you!
private: System::Void richTextBoxCommentaire_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (e->KeyValue == (char)13)
{
MessageBox::Show ("Please enter Espace or Tab");
//To delete this Key??
}
}
sorry, using the previewKeyDown should have worked but try the next method :
Use the KeyDown event to filter the desired keys by setting the suppressKeyPress to true as you can see in the example below (the example is in C# for readability but conversion to C++ CLI should be trivial :) :
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = e.KeyCode == Keys.Enter;
}
Can we use waveViever to plot waveform while recording?
private NAudio.Wave.WaveIn wi = null;
int waveInDevices = NAudio.Wave.WaveIn.DeviceCount;
WaveFileWriter waveWriter = null;
SaveFileDialog save;
private void button2_Click(object sender, EventArgs e)
{
save = new SaveFileDialog();
save.Filter = "Wave File (*.wav)|*.wav;";
if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
int deviceNumber = 0;
wi = new WaveIn();
wi.DeviceNumber = deviceNumber;
wi.WaveFormat = new WaveFormat(44100, WaveIn.GetCapabilities(deviceNumber).Channels);
wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);
waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, wi.WaveFormat);
wi.StartRecording();
timer1.Start();
}
private void wi_DataAvailable(object sender, WaveInEventArgs e)
{
if (waveWriter == null) return;
waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded);
waveWriter.Flush();
}
private void timer1_Tick(object sender, EventArgs e)
{
waveViewer1.WaveStream = new WaveFileReader(save.Filename);
}
I am using that code statement to record file and want to read file every tick interval of timer and plot waveform in waveViewer.However it gives an error that "File is in use by another process". Is there anyway to do this. Should i use first overload of WaveFileReader(Stream streamInput)? If yes, please can you give an example about first overload.
I wouldn't recommend trying to use waveViewer, although you could take a copy of the code and use it as a basis. If you look at the WPF demo code in the NAudio repository, it supports drawing the waveform while you are recording.
The basic principle is every time the DataAvailable event fires, calculate the max peaks of the recorded audio and add that to your waveform display.
I am trying to make my first WP8 app but, i got a problem. I try to navigate to another page using the code below, but VS12 throws a error.
What am I doing wrong?
private void btnBMIBereken_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/BMI_Bereken.xaml", UriKind.Relative));
}
Your code is correct for navigating, just make sure the Page 'BMI_Bereken.xaml' actual exists at the root of your project.
Clean solution first and then rebuild again (right click on project/solution -> clean)
Then if it still crashes, try to use System.Windows.RoutedEventArgs e instead of RoutedEventArgs e
Guys i found the problem.
I use a self made button style for my buttons and i got on the visualstate pressed some wrong code. In fact I was trying to set the background collor of the button in the place of the name target name.
See the code below for what i did wrong.
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="#FF009AD3">
I know very stupid, but I want to thank everyone for the help.
Try this
private void btnBMIBereken_Click(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
this.NavigationService.Navigate(new Uri("/BMI_Bereken.xaml", UriKind.Relative));
});
}
You could do something like this:
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (txtDriverId.Text == "D0001" && txtPassword.Password == "open")
{
Frame.Navigate(typeof(VehicleCondition));
}
}