Reputation: 31
How can I stop the AxWindowsMediaPlayer manually on button click? I am developing an application in WPF and using VS 2015.
<WindowsFormsHost x:Name="winhost" HorizontalAlignment="Stretch" VerticalAlignment="Center" Background="Transparent" Visibility="Hidden">
<ax:AxWindowsMediaPlayer x:Name="axwmp" />
</WindowsFormsHost>
Upvotes: 1
Views: 2960
Reputation: 576
If you have a commandbinding on the button, or watching the button click event programmatically, you can execute this command:
axWindowsMediaPlayerObject.Ctlcontrols.stop();
Here is my code, how i tried it:
WPF - MainWindow
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Row="0" Click="ButtonBase_OnClick">Test</Button>
<WindowsFormsHost Grid.Row="1" x:Name="winhost" HorizontalAlignment="Stretch" VerticalAlignment="Center" Background="Transparent">
<ax:AxWindowsMediaPlayer x:Name="axwmp" />
</WindowsFormsHost>
</Grid>
Code Behind
public partial class MainWindow : Window
{
private AxWindowsMediaPlayer mPlayer;
public MainWindow()
{
InitializeComponent();
mPlayer = axwmp;
mPlayer.BeginInit();
mPlayer.EndInit();
mPlayer.Ctlenabled = true;
mPlayer.URL = @"http://www.mediacollege.com/audio/tone/files/100Hz_44100Hz_16bit_30sec.mp3";
mPlayer.Ctlcontrols.play();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
mPlayer.Ctlcontrols.stop();
}
}
Btw, you need to have the MediaPlayer.exe outputed to your exe.
Upvotes: 2