This article was automatically translated using Google
It has been six days since I wrote this player, and most of the functions have been implemented so far. The most important thing I can think of is the home page.
The most important thing is indeed the least important to me. It is mainly because I listen to songs first by query, and second by selecting singers. It seems that a new function needs to be added here. The current page is from singers to albums and then to songs. I seem to I should make a page of all songs, or use the last.fm interface to make a Top10 hit song, or define the hit song based on my own play count
lyrics! lyrics! lyrics! The important thing is said three times. In fact, there are ready-made wheels that can be used flutter_lyric 2.0.4+6. Thinking about downloading the lyrics and then doing the matching, it’s a bit…let’s put it away for now, and I’ll talk about it after I find a way to import lyrics in batches
Fuzzy search + simplified and traditional search
This function is what I have always wanted, but sonixd does not have it. After all, it was developed by foreigners, so there is no such requirement. But my demand is very big, because there is a mixture of simplified and traditional Chinese in the music library. Without this search, it makes me crazy. Today, I mainly realize this function.
I am going to write two search entries, one is a small column with a height of 25 at the top for quick search, and a drop-down pop-up window is added to select songs. Writing another search page is mainly to display more content. In fact, it is enough to keep one. Let’s do the function first. Anyway, it can be used in both interfaces.
Simplified and traditional conversion
I didn’t think about this at all before, but today I was thinking whether it can be solved by changing the code. I tried it, it was just a display method, and then I wanted to use the API to do this, but just such a small function leads to an API. I felt uncomfortable and thought about it. I saw an article on CDSN, saying that you don’t have to worry about it. If you want to do it, you can just make a dictionary. Anyway, the commonly used Chinese words are only 4000 to 6000 words.
The trouble is that you have to get two strings, and then the index corresponds, which is very annoying. After searching for a long time, I found a [kind brother released it](https://blog.csdn.net/great_domino/article/details/ 280162), I don’t know when it will be gone, I will put it in the back later, and anyone who wants to search can use it for free in the future.
The big brother is JS, but the implementation logic is the same, just come to the code
String traditional = ""; for (int i = 0; i <= simplified.length - 1; i++) { //循环把传入的简体取出来 String _temp = simplified[i]; //找到简体对应的序号 int dddd = xx.indexOf(_temp); //如果能找到序号,就填入对应的繁体 if (dddd > 0) { traditional += yy[dddd]; } else { //如果找不到序号就把简体写进去,无所谓啦,说不定后面数据like也能搜出来呢 traditional += _temp; } } //返回繁体 return traditional; }
So the difficulty of this method is not in the programming, but in the two strings provided by a kind brother, otherwise you will be crazy if you do it yourself!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
getSongByName(String title, String title2) async { try { final db = await instance.db; //如果繁体没查到就用简体查两次呗 if (title2 == "") title2 = title; //这里的%就是模糊查找,前后放,其实还可以把字符串拆开一个字一个字的放...不过没那么无聊吧,哈哈哈哈 var res = await db.rawQuery( "SELECT * FROM $SongsTable WHERE title like '%$title%' or title like '%$title2%' ");
_getSongsbyName() async { String _title1 = searchController.text; String _title2 = ""; List<Songs> _list = []; _title2 = await converToTraditional(_title1); final _songsList = await BaseDB.instance.getSongByName(_title1, _title2); if (_songsList != null) { for (var element in _songsList) { Songs _tem = element; _list.add(_tem); } setState(() { _songs = _list; }); } }
Then the effect will come out! back is really nice, a song shows fuzzy search and simplified and traditional search
Lyrics
In fact, I didn’t think about how to display the lyrics. This thing is necessary when you don’t have it. When you have it, the time to read the lyrics may only account for 1% of the total usage time.
As for the display methods, there are three ways. On the desktop, you can create a floating window like a cool dog, or on the Mac, it will be in the status bar at the top, and on IOS, click the picture of the current song and pop up a bottom The pop-up page is shown in
So I removed the original Now Playing page from the left navigation bar, thinking that clicking on the song picture is the most appropriate trigger for Now Playing. But I just remembered a problem when I wrote this. My entire form is written in body, which is fine on the desktop. Split it into appBar and bottomNavigationBar, but it is not necessarily, because I wrote the route myself, so there is no problem of passing the status. Let’s talk about it when it is adapted. It’s good not to have the top, but there are some The problem is that when it pops up, it will cover the lower part, because the bottom is not bottom, but there are always various ways to do it. Let’s do it today, sleep, birthday
Adjusted the layout
According to the idea of last night, I used the appbar, but in order to simplify the code, I did not use the default AppBar control. Anyway, it is also extends StatefulWidget implements PreferredSizeWidget, so I also write it like this, and I can directlyreturnMy original code, this is simple, just use the get method to inject the height.
Flutter is still very powerful. I have been debugging based on the desktop side before, but I just thought about how to deal with the mobile side when writing. Today, I opened the IOS virtual machine and took a look. It is very good. Basically, it can be adapted directly without major changes.
Isn’t this the simplest StatefulWidget you have ever seen? It just doesn’t deserve to be called ful, right? ! ! Hahaha, I will add a search box and a pop-up window under the search box later, and then it will be called ful. The current logic is to click the search button to jump directly to the search page, and the subsequent logic should be to click the search button to slide out the search box from the left, and enter within three results will pop up, and then there are more at the bottom, click Go to the search page. When you find a song, you can order the song directly in the drop-down box and play it directly.
That’s it for today, I don’t work for my birthday, and I originally wanted to remove the collection function. After all, it is based on my own music server, so what are the favorites? Aren’t all my own songs are my favorites… I didn’t decide whether to keep it, because there is no such thing in the api, if I want it, I can only add it directly In the database, does this make sense? To quickly find: 1, search; 2, playlist, right?
There are two playlists and homepages at the back. After finishing it, you can go to the biggest lyrics function. The place has been reserved, and there is also a wheel flutter_lyric that can be used directly Use it, put it to the end.
The follow-up should be to get the playlist and homepage done first, then start to adapt to the mobile terminal (it may be finished in two days), and then find an api to get singer information. The current album pictures are MusicBrainz Picard, there is no singer information, good-looking photos and profiles, etc., you should be able to use the API of NetEase Cloud, this can be cached in the database, and it is enough to get it once , so you can take your time when it is unstable, and there are ready-made wheels that can be written with NeteaseCloudMusicApi NodeJS, it should be easy to get flutter to use