Skip to content

Commit ae72cc4

Browse files
author
hezhilong
committed
add bass dll
1 parent b33c0a4 commit ae72cc4

File tree

8 files changed

+217
-62
lines changed

8 files changed

+217
-62
lines changed

FishFM/FishFM.csproj

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,30 @@
77
<FileVersion>0.0.1</FileVersion>
88
<NeutralLanguage>en-CN</NeutralLanguage>
99
<UseAppHost>true</UseAppHost>
10+
11+
<CFBundleName>FishFM</CFBundleName>
12+
<CFBundleDisplayName>FishFM</CFBundleDisplayName>
13+
<CFBundleIdentifier>fun.ifish</CFBundleIdentifier>
14+
<CFBundleVersion>1.0.0</CFBundleVersion>
15+
<CFBundlePackageType>APPL</CFBundlePackageType>
16+
<CFBundleSignature>????</CFBundleSignature>
17+
<CFBundleExecutable>FishFM</CFBundleExecutable>
18+
<CFBundleIconFile>FishFM.icns</CFBundleIconFile>
19+
<NSPrincipalClass>NSApplication</NSPrincipalClass>
20+
<NSHighResolutionCapable>true</NSHighResolutionCapable>
1021
</PropertyGroup>
1122
<ItemGroup>
1223
<Folder Include="Models\" />
1324
<AvaloniaResource Include="Assets\**" />
1425
</ItemGroup>
1526
<ItemGroup>
16-
<PackageReference Include="Avalonia" Version="0.10.3" />
17-
<PackageReference Include="Avalonia.Desktop" Version="0.10.3" />
18-
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.3" />
19-
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.3" />
27+
<PackageReference Include="Avalonia" Version="0.10.13" />
28+
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
29+
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.13" />
30+
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
2031
<PackageReference Include="LiteDB" Version="5.0.11" />
2132
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
33+
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
2234
</ItemGroup>
2335
<ItemGroup>
2436
<Compile Update="Views\CaptureWIndow.axaml.cs">
@@ -32,4 +44,15 @@
3244
<HintPath>..\..\..\Downloads\Bass24.Net\standard\Bass.Net.dll</HintPath>
3345
</Reference>
3446
</ItemGroup>
47+
<ItemGroup>
48+
<None Update="libbass.dylib">
49+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
50+
</None>
51+
<None Update="bass.dll">
52+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
53+
</None>
54+
<None Update="libbass.so">
55+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
56+
</None>
57+
</ItemGroup>
3558
</Project>

FishFM/Helper/DbHelper.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using FishFM.Models;
34
using LiteDB;
@@ -9,6 +10,7 @@ public class DbHelper
910
{
1011
private const string FmSongTable = "t_fm_songs";
1112
private const string LikeTable = "t_liked_songs";
13+
private static Random Rdm = new Random();
1214

1315
public static bool UpsertSongs(List<SongResult> list, string date, string type)
1416
{
@@ -26,8 +28,59 @@ public static List<SongResult> GetSongs(string date, string type)
2628
{
2729
using var db = new LiteDatabase("./MyFM.db");
2830
var col = db.GetCollection<DbSong>(FmSongTable);
29-
var list = col.Query().Where(s => s.FmType == type && s.AddDate == date).ToList();
30-
List<SongResult> results = new List<SongResult>(list.Count);
31+
var list = col.Query()
32+
.Where(s => s.FmType == type && (string.IsNullOrEmpty(date) || s.AddDate == date)).ToList();
33+
var results = new List<SongResult>(list.Count);
34+
foreach (var dbSong in list)
35+
{
36+
var song = JsonConvert.DeserializeObject<SongResult>(dbSong.Text);
37+
if (song != null)
38+
{
39+
results.Add(song);
40+
}
41+
}
42+
return results;
43+
}
44+
45+
public static SongResult? GetLastSong(string type)
46+
{
47+
using var db = new LiteDatabase("./MyFM.db");
48+
var col = db.GetCollection<DbSong>(FmSongTable);
49+
var lastSong = col.Query()
50+
.Where(s => s.FmType == type).OrderByDescending(s=>s.AddDate).Limit(1).FirstOrDefault();
51+
if (lastSong == null)
52+
{
53+
return null;
54+
}
55+
return JsonConvert.DeserializeObject<SongResult>(lastSong.Text);
56+
}
57+
58+
public static List<SongResult> GetSongsByIds(List<string> ids)
59+
{
60+
using var db = new LiteDatabase("./MyFM.db");
61+
var col = db.GetCollection<DbSong>(FmSongTable);
62+
var list = col.Query()
63+
.Where(s => ids.Contains(s.Id)).ToList();
64+
var results = new List<SongResult>(list.Count);
65+
foreach (var dbSong in list)
66+
{
67+
var song = JsonConvert.DeserializeObject<SongResult>(dbSong.Text);
68+
if (song != null)
69+
{
70+
results.Add(song);
71+
}
72+
}
73+
return results;
74+
}
75+
76+
public static List<SongResult> GetRandomSongs()
77+
{
78+
using var db = new LiteDatabase("./MyFM.db");
79+
var col = db.GetCollection<DbSong>(FmSongTable);
80+
var offset = Rdm.Next(0, col.Count());
81+
var list = col.Query()
82+
.Limit(1).Offset(offset).ToList();
83+
var results = new List<SongResult>(list.Count);
3184
foreach (var dbSong in list)
3285
{
3386
var song = JsonConvert.DeserializeObject<SongResult>(dbSong.Text);

FishFM/ViewModels/MainWindowViewModel.cs

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class MainWindowViewModel : ViewModelBase
2020
private DOWNLOADPROC? _downloadProc;
2121
private BASSTimer? _updateTimer;
2222
private int _currentStream;
23+
private bool _isDiscoveryInit;
2324

2425
#region Params
2526

@@ -97,7 +98,7 @@ public int TabIndex
9798
set => this.RaiseAndSetIfChanged(ref _tabIndex, value);
9899
}
99100

100-
private const string DefaultTip = "有的鱼是永远都关不住的,因为他们属于天空";
101+
private const string DefaultTip = "有的鱼是永远都关不住的,因为他们属于天空";
101102
private string _tipText = DefaultTip;
102103
public string TipText
103104
{
@@ -120,48 +121,27 @@ public MainWindowViewModel()
120121

121122
#endregion
122123

123-
public void ShowCapture()
124+
public void PlayPauseMusic()
124125
{
125-
126+
if (Playing)
127+
{
128+
Pause();
129+
}
130+
else
131+
{
132+
Play();
133+
}
126134
}
127135

128136
private void InitBassAndSongs()
129137
{
130138
Task.Factory.StartNew(() =>
131139
{
132140
BassInit();
133-
InitSongs();
141+
RefreshList();
134142
});
135143
}
136144

137-
private void InitSongs()
138-
{
139-
var date = new DateTime().ToString("yyyy-MM-dd");
140-
var type = "daily";
141-
var songs = DbHelper.GetSongs(date, type);
142-
if (songs.Count <= 0)
143-
{
144-
var url = "https://ifish.fun/api/music/daily?t=all";
145-
using var client = new HttpClient();
146-
var resp = client.GetAsync(url).Result;
147-
if (!resp.IsSuccessStatusCode) return;
148-
var html = resp.Content.ReadAsStringAsync().Result;
149-
if (String.IsNullOrEmpty(html))
150-
{
151-
return;
152-
}
153-
var list = JsonConvert.DeserializeObject<List<SongResult>>(html);
154-
if (list == null)
155-
{
156-
return;
157-
}
158-
songs = list;
159-
DbHelper.UpsertSongs(list, date, type);
160-
}
161-
_songList = songs;
162-
PlayRandom();
163-
}
164-
165145
private void PlayRandom()
166146
{
167147
if (_songList == null)
@@ -235,7 +215,7 @@ private void PlaySong(SongResult? songResult)
235215
if (_playTask != null && _cancellationToken != null)
236216
{
237217
_cancellationToken.Cancel();
238-
_playTask.Wait();
218+
_playTask.Wait(1000);
239219
_playTask.Dispose();
240220
_cancellationToken.Dispose();
241221
}
@@ -283,7 +263,12 @@ private void PlaySong(SongResult? songResult)
283263
{
284264
Bass.BASS_Start();
285265
}
286-
if (_currentStream != 0 && Bass.BASS_ChannelPlay(_currentStream, true))
266+
if (_currentStream == 0)
267+
{
268+
PlayNext();
269+
return;
270+
}
271+
if (Bass.BASS_ChannelPlay(_currentStream, true))
287272
{
288273
TrackLength = Bass.BASS_ChannelBytes2Seconds(_currentStream,
289274
Bass.BASS_ChannelGetLength(_currentStream));
@@ -316,7 +301,14 @@ private void CachePlayingSong(IntPtr buffer, int length, IntPtr user)
316301

317302
public void PlayNext()
318303
{
319-
PlayRandom();
304+
if (TabIndex == 1)
305+
{
306+
RefreshList();
307+
}
308+
else
309+
{
310+
PlayRandom();
311+
}
320312
}
321313

322314
public void PlayPrev()
@@ -398,5 +390,69 @@ private void SetTipText(string tip)
398390
TipText = DefaultTip;
399391
}));
400392
}
393+
394+
public void RefreshList()
395+
{
396+
List<SongResult> songs;
397+
var type = "daily";
398+
var date = DateTime.Now.ToString("yyyy-MM-dd");
399+
switch (TabIndex)
400+
{
401+
case 0:
402+
songs = DbHelper.GetSongs(date, type);
403+
if (songs.Count <= 0)
404+
{
405+
var list = getSongsByType("xm");
406+
if (list == null)
407+
{
408+
return;
409+
}
410+
songs = list;
411+
DbHelper.UpsertSongs(list, date, type);
412+
}
413+
break;
414+
case 1:
415+
var lastSong = DbHelper.GetLastSong("init");
416+
if (lastSong == null && !_isDiscoveryInit)
417+
{
418+
_isDiscoveryInit = true;
419+
Task.Factory.StartNew(() =>
420+
{
421+
var list = getSongsByType("init");
422+
if (list == null)
423+
{
424+
return;
425+
}
426+
DbHelper.UpsertSongs(list, date, "init");
427+
_isDiscoveryInit = false;
428+
});
429+
}
430+
songs = DbHelper.GetRandomSongs();
431+
break;
432+
case 2:
433+
var ids = DbHelper.GetAllLikedSong();
434+
songs = ids.Count > 0 ? DbHelper.GetSongsByIds(ids) : DbHelper.GetRandomSongs();
435+
break;
436+
default:
437+
songs = DbHelper.GetRandomSongs();
438+
break;
439+
}
440+
_songList = songs;
441+
PlayRandom();
442+
}
443+
444+
private List<SongResult>? getSongsByType(string type)
445+
{
446+
var url = "https://ifish.fun/api/music/daily?t="+type;
447+
using var client = new HttpClient();
448+
var resp = client.GetAsync(url).Result;
449+
if (!resp.IsSuccessStatusCode) return null;
450+
var html = resp.Content.ReadAsStringAsync().Result;
451+
if (string.IsNullOrEmpty(html))
452+
{
453+
return null;
454+
}
455+
return JsonConvert.DeserializeObject<List<SongResult>>(html);
456+
}
401457
}
402458
}

0 commit comments

Comments
 (0)