Skip to content

Commit a4ce5e6

Browse files
Change to be self-contained, no needing TagLibUnity
1 parent 3ef0d99 commit a4ce5e6

File tree

5 files changed

+112
-8
lines changed

5 files changed

+112
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ riderModule.iml
77
Links/
88
.idea/
99
*.zip
10-
Staging/Mods/VoidSpeaker.dll
10+
Staging/
1111

1212
VoidSpeaker.sln.DotSettings.user

Music/Helpers/TagLibWrapper.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.IO;
2+
3+
namespace WeatherElectric.VoidSpeaker.Music.Helpers;
4+
5+
internal static class TagLibWrapper
6+
{
7+
public enum Tag
8+
{
9+
Title,
10+
Artist,
11+
Album,
12+
AlbumArtist,
13+
Genre,
14+
Year,
15+
Track,
16+
Disc,
17+
Composer,
18+
Conductor
19+
}
20+
21+
private static string _tag;
22+
23+
public static string GetTag(string filepath, Tag tag)
24+
{
25+
var tagLibFile = global::TagLib.File.Create(filepath);
26+
_tag = tag switch
27+
{
28+
Tag.Title => tagLibFile.Tag.Title,
29+
Tag.Artist => tagLibFile.Tag.FirstPerformer,
30+
Tag.Album => tagLibFile.Tag.Album,
31+
Tag.AlbumArtist => tagLibFile.Tag.FirstAlbumArtist,
32+
Tag.Genre => tagLibFile.Tag.FirstGenre,
33+
Tag.Year => tagLibFile.Tag.Year.ToString(),
34+
Tag.Track => tagLibFile.Tag.Track.ToString(),
35+
Tag.Disc => tagLibFile.Tag.Disc.ToString(),
36+
Tag.Composer => tagLibFile.Tag.FirstComposer,
37+
Tag.Conductor => tagLibFile.Tag.Conductor,
38+
_ => null
39+
};
40+
if (_tag == null)
41+
{
42+
ModConsole.Error($"{filepath}'s {tag.ToString()} field is null!");
43+
return null;
44+
}
45+
return _tag;
46+
}
47+
48+
public static Texture2D GetCover(string filepath)
49+
{
50+
var tagLibFile = TagLib.File.Create(filepath);
51+
var picture = tagLibFile.Tag.Pictures[0];
52+
if (picture == null)
53+
{
54+
ModConsole.Error($"{filepath}'s album art field is null!");
55+
return null;
56+
}
57+
var texture = new Texture2D(2, 2);
58+
// ReSharper disable once InvokeAsExtensionMethod, unhollowed unity extensions don't work well, have to call them directly
59+
ImageConversion.LoadImage(texture, picture.Data.Data, false);
60+
return texture;
61+
}
62+
63+
public static string GetFilename(string filepath)
64+
{
65+
var title = Path.GetFileName(filepath);
66+
return title;
67+
}
68+
}

Music/MusicPlayer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BoneLib.Notifications;
2-
using WeatherElectric.TagLibUnity;
32
using WeatherElectric.VoidSpeaker.Music.Helpers;
43

54
namespace WeatherElectric.VoidSpeaker.Music;
@@ -56,9 +55,9 @@ private static void SendNotification(MusicFile musicFile)
5655
{
5756
if (Preferences.UseTagLib.Value)
5857
{
59-
var songName = TagLib.GetTag(musicFile.FilePath, TagLib.Tag.Title);
60-
var artistName = TagLib.GetTag(musicFile.FilePath, TagLib.Tag.Artist);
61-
Texture2D albumArt = TagLib.GetCover(musicFile.FilePath);
58+
var songName = TagLibWrapper.GetTag(musicFile.FilePath, TagLibWrapper.Tag.Title);
59+
var artistName = TagLibWrapper.GetTag(musicFile.FilePath, TagLibWrapper.Tag.Artist);
60+
Texture2D albumArt = TagLibWrapper.GetCover(musicFile.FilePath);
6261

6362
Notification notif = new Notification()
6463
{

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# VoidSpeaker
2+
A music player for BONELAB
3+
4+
# IMPORTANT!
5+
* DEPENDING ON HOW MANY MP3 FILES YOU PUT IN THE FOLDER, THE GAME MAY TAKE LONGER TO START UP!
6+
* THIS IS INEVITABLE! PUTTING IT ON ANOTHER THREAD CRASHES THE GAME, AND IF IT WERE ASYNC IT MAY NOT BE FULLY LOADED BY THE TIME YOU SPAWN ONE IN, CAUSING PROBLEMS!
7+
8+
# Setup
9+
## Mod
10+
### Installation
11+
* Place TagLibSharp.dll in the UserLibs folder
12+
* Place VoidSpeaker.dll in the Mods folder and run the game once
13+
### Preferences
14+
* In WeatherElectric.cfg, all preferences for the mod are in the VoidSpeaker category
15+
* You can also edit them in game through BoneMenu.
16+
## Custom Audio
17+
### Requirements
18+
* MP3 files
19+
* [Mp3Tag](https://www.mp3tag.de/en/)
20+
### File Setup
21+
* Drag your MP3 files into Mp3Tag
22+
* Select all of them
23+
![image](https://github.com/WeatherElectric/MediaPlayer/assets/30084485/ccbcff5c-02ab-41cf-90d1-0e73f637f6a0)
24+
* Right click and hit "Actions"
25+
* Create a new action and name it anything
26+
* Add an "Adjust cover" action to it
27+
![image](https://github.com/WeatherElectric/MediaPlayer/assets/30084485/e41c2489-dfef-4c3e-adb8-a148e5085100)
28+
* Set the max size to "336"
29+
* Deselect all action groups EXCEPT the one you just made
30+
![image](https://github.com/WeatherElectric/MediaPlayer/assets/30084485/1f8ed712-3326-462d-945a-d9df1ffd93f6)
31+
* Hit "OK"
32+
### Installation
33+
* Place your MP3 files into UserData/Weather Electric/Void Speaker

VoidSpeaker.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<Reference Include="SLZ.Marrow.SDK">
5656
<HintPath>Links\MelonLoader\Managed\SLZ.Marrow.SDK.dll</HintPath>
5757
</Reference>
58+
<Reference Include="TagLibSharp">
59+
<HintPath>Staging\UserLibs\TagLibSharp.dll</HintPath>
60+
</Reference>
5861
<Reference Include="UnhollowerBaseLib">
5962
<HintPath>Links\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
6063
</Reference>
@@ -64,8 +67,8 @@
6467
<Reference Include="UnityEngine.AudioModule">
6568
<HintPath>Links\MelonLoader\Managed\UnityEngine.AudioModule.dll</HintPath>
6669
</Reference>
67-
<Reference Include="TagLibUnity">
68-
<HintPath>Links\Mods\TagLibUnity.dll</HintPath>
70+
<Reference Include="UnityEngine.ImageConversionModule">
71+
<HintPath>Links\MelonLoader\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
6972
</Reference>
7073
</ItemGroup>
7174
<ItemGroup>
@@ -74,6 +77,7 @@
7477
<Compile Include="GlobalUsings.cs"/>
7578
<Compile Include="Music\Files\MusicFile.cs" />
7679
<Compile Include="Music\Helpers\HelperMethods.cs" />
80+
<Compile Include="Music\Helpers\TagLibWrapper.cs" />
7781
<Compile Include="Music\MusicList.cs" />
7882
<Compile Include="Music\MusicLoader.cs" />
7983
<Compile Include="Main.cs"/>
@@ -90,6 +94,6 @@
9094
<PropertyGroup>
9195
<PostBuildEvent>COPY "$(TargetPath)" "$(SolutionDir)\Links\Mods"
9296
COPY "$(TargetPath)" "$(SolutionDir)Staging\Mods"
93-
</PostBuildEvent>
97+
COPY "$(SolutionDir)README.md" "$(SolutionDir)Staging"</PostBuildEvent>
9498
</PropertyGroup>
9599
</Project>

0 commit comments

Comments
 (0)