简体   繁体   English

WPF和MusicPlayer

[英]WPF and MusicPlayer

I received a request to create a Music Player with specific features. 我收到了创建具有特定功能的音乐播放器的请求。

This Music Player will Play music in modality "Random" (first request) downloading songs from a folder and one more request is to change "Genre" of music each 4 hours for example: 此音乐播放器将播放“随机”模式的音乐(第一个请求),从文件夹下载歌曲,另一个请求是每4小时更改音乐的“流派”,例如:

  • from 8am to 12am :it plays "Romantic" songs; 从8am到12am:播放“浪漫”歌曲;
  • from 12am to 4pm :it plays "Latin" songs; 从12am到4pm:播放“拉丁”歌曲;
  • from 4pm to 8pm : it plays "Rock" songs; 从4pm到8pm:播放“ Rock”歌曲;
  • from 8pm to midnight : it plays "Dance" music; 从晚上8点到午夜:播放“ Dance”音乐;

My purpose is to create different song's folder for each Genre and give respective TitleName (Romantic, Latin, Rock, etc.) and when start the music player will automatic download the song's folder following the time slot. 我的目的是为每个流派创建不同的歌曲文件夹,并指定各自的TitleName(浪漫,拉丁,摇滚等),并且音乐播放器在启动时会在相应的时间段后自动下载歌曲的文件夹。

So I ask you some advice about the code how organize these features because I don't know how change the Genre Music for hours and put the music player in modality Random. 因此,我想向您咨询一些有关代码如何组织这些功能的建议,因为我不知道如何在数小时内改变流派音乐并将音乐播放器置于随机状态。

Here's an approach. 这是一种方法。

Read all the ID3 tags for the MP3 files enqued in the playlist or folder using C# ID3 Library or any other ID3 tag reader for MP3 files. 使用C#ID3库或用于MP3文件的任何其他ID3标签阅读器,读取播放列表或文件夹中排队的MP3文件的所有ID3标签。 Probe the playlist, read ID3 tags, create a repo. 探查播放列表,读取ID3标签,创建存储库。 Set the timer & pick a genre from your already read repo 设置计时器并从您已阅读的回购中选择一种类型

You say that you are downloading songs from a folder, which leads me to believe that there is a server that is shuttling information to the media player. 您说您正在从文件夹下载歌曲,这使我相信有一个服务器正在将信息传送到媒体播放器。

I'd put the logic for this onto the server side. 我将逻辑放在服务器端。 Just use whatever regular media player is out there. 只需使用任何常规的媒体播放器即可。

Then, on the server side, generate a feed of some sort which feeds the URLs of the songs to download depending on the time of day on the server (adjusted by an offset if the client supplies one). 然后,在服务器端,生成某种类型的提要,该提要根据服务器上一天中的时间来提要下载的歌曲的URL(如果客户端提供一个,则通过偏移量进行调整)。

Then, your program would read the feed and get the urls of the songs to play, and just feed the playlist to the media player (or download the songs and feed them to the media player) based on what the server tells you. 然后,您的程序将读取提要,并获取要播放的歌曲的URL,然后根据服务器告诉您的内容,将播放列表提供给媒体播放器(或下载歌曲并将其提供给媒体播放器)。

One Notion that would appear useful in your app is the concept of Song sources. 在您的应用中显示有用的一种概念是Song来源的概念。 A song source would essentially be an enumerable item that provides access to songs. 歌曲来源从本质上讲是可枚举的项目,可提供对歌曲的访问。 This could firstly be an interface. 首先可以是一个接口。

That way you have the abstract concept of a piece of code providing lists of songs. 这样,您就可以理解一段提供歌曲列表的代码的抽象概念。 The actual player would access any implementation of ISongSource to get the next song to play, and play it. 实际的播放器将访问ISongSource的任何实现,以播放下一首歌曲并进行播放。 The playing bit, I am afraid I can't help you there. 发挥作用,恐怕我在这里不能为您提供帮助。 If all else fails you could create m3u files (mp3 playlists) from your song sources and start eg Winamp via Process.Start, passing the newly created playlist. 如果所有其他方法都失败,则可以从歌曲源创建m3u文件(mp3播放列表),然后通过Process.Start启动Winamp,例如传递新创建的播放列表。 In fact, this sounds like a neat version 1. 实际上,这听起来像是一个简洁的版本1。

If you want to code everything you may need a piece of code to read ID3 tags from an mp3 file (If you are playing mp3 files). 如果要编写所有代码,则可能需要一段代码才能从mp3文件中读取ID3标签(如果正在播放mp3文件)。 You should see this as independent functionality and chances are that there is already something available. 您应该将其视为独立的功能,并且可能已经有可用的功能。 The ID3 tagging is not very complicated, if I remember well there are defined byte offsets at the head of the mp3 file. ID3标记不是很复杂,如果我记得很好,在mp3文件的开头有定义的字节偏移。

Based on this you should be able to implement song sources that consider ID3 tags in order to decide what song should be part of the source. 基于此,您应该能够实现考虑了ID3标签的歌曲源,以便确定哪些歌曲应成为该源的一部分。

Finally there is the UI. 最后是UI。 That is a whole world on its own, especially if you would have a skinnable thing. 那就是整个世界本身,特别是如果您有皮肤的东西。 But with a decent WPF book and some proof of concepts you should be on your way to get something done. 但是,只要拥有一本不错的WPF书和一些概念证明,您就应该可以完成工作。

Happy coding! 编码愉快!

Does it have to be a brand new media player? 它必须是一个全新的媒体播放器吗? Depending on your requirements, you might consider wrapping Windows Media Player to do this. 根据您的要求,您可以考虑包装Windows Media Player来执行此操作。 Here's a good starting point: 这是一个很好的起点:

(Windows Media Player) Object Model Reference for Visual Basic .NET and C# (Windows Media Player)Visual Basic .NET和C#的对象模型参考

I've used the Windows Media Player SDK to do something similar to this. 我已经使用Windows Media Player SDK来执行类似的操作。 It's not the most straightforward API, but it's just one DLL, and it's relatively easy to send commands to it to get WMP to do stuff. 它不是最简单的API,但只是一个DLL,向它发送命令以使WMP可以做些事情相对容易。 Here's a link to the various SDK versions (which include the wmppia.dll you'll need): 这是各种SDK版本的链接(其中包括您需要的wmppia.dll):

Windows Media Downloads Windows Media下载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM