如何在单击按钮时手动停止AxWindowsMediaPlayer?我正在WPF中开发一个应用程序,并使用VS 2015。
<WindowsFormsHost x:Name="winhost" HorizontalAlignment="Stretch" VerticalAlignment="Center" Background="Transparent" Visibility="Hidden">
<ax:AxWindowsMediaPlayer x:Name="axwmp" />
</WindowsFormsHost>发布于 2016-05-23 11:24:56
如果按钮上有命令绑定,或者以编程方式查看按钮单击事件,则可以执行以下命令:
axWindowsMediaPlayerObject.Ctlcontrols.stop();这是我的代码,我是如何尝试的:
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>代码在中的应用
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();
}
}顺便说一句,您需要将MediaPlayer.exe输出到您的exe。
https://stackoverflow.com/questions/37389510
复制相似问题