如何选择并播放列表中的多首歌曲?
我有一个要求,我需要使用 wpf 在窗口上播放多首音频歌曲。任何人都可以建议实现此目的的最佳方法。
我有窗户。我将在列表框中显示歌曲列表。用户应该能够从列表框中选择多首歌曲并单击播放。
我必须一一播放用户选择的所有音频歌曲。
我会感谢你的帮助。
I have a requirement, I need to play multiple audio songs on window using wpf.Can anyone suggest the best way to implement this.
I have window. There I will display the list of the songs in list box. User should able to select the multiple songs from the list box and click play.
I have to play the all audio songs selected by user one by one.
I will appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是使用一个 ListBox 控件,并将其 ItemsSource 属性绑定到某个集合(例如“SongList”)。
在页面上有一个 MediaElement 控件监听下一首歌曲
当用户单击表单上的按钮时,当前选定的项目将添加到队列中。通过读取 ListBox.SelectedItems 属性可以找到当前选定的项目。
然后,您开始播放队列中的第一个项目,当引发
MediaElement.MediaEnded
事件时,将当前正在播放的项目替换为队列中的下一个项目(如果有可用的项目)。您将执行此操作,直到用户点击预定义的停止按钮。
playNext()
方法很简单(确保 CurrentPlaying 属性引发
INotifyPropertyChanged.PropertyChanged
事件)MainWindow.xaml.cs
<强>MainWindow.xaml
The easiest way to do this would be to have a ListBox control with its ItemsSource property bound to some collection ("SongList" for example).
Have a MediaElement control on the page listening for the next song
When the user clicks a button on the form, the currently selected items are added to a queue. The currently selected items can be found by reading the ListBox.SelectedItems property.
You then start playing the first item in the queue, and when the
MediaElement.MediaEnded
event is raised, replace the currently playing item with the next item in the queue if there is one available.You would do this until the user hit a predefined stop button.
The
playNext()
method would just simply be(Make sure that the CurrentlyPlaying property raises the
INotifyPropertyChanged.PropertyChanged
event)MainWindow.xaml.cs
MainWindow.xaml