jmshrv / finamp

A Jellyfin music client for mobile
Mozilla Public License 2.0
1.87k stars 123 forks source link

Add support for Linux, maybe publish on Flathub #40

Open GabMus opened 3 years ago

GabMus commented 3 years ago

Hi, I just tried Finamp and I gotta say it's a pretty great way to listen to Jellyfin music. I was wondering if you wanted to add support for Linux, since this is built with Flutter. This way we could use it on our desktop PCs as well as on the new Linux phones.

Publishing on Flathub would be an added value, you can look at Fluffy chat as an example for another Flutter app that has been published on Flathub.

jmshrv commented 3 years ago

I'd love to create a Linux version, but not all Flutter packages run on all platforms. Many use platform code to use native Android/iOS stuff. Here are all of the packages that are currently incompatible with Linux:

The only packages that are really essential there are the audio packages. I could probably create a desktop interface for device_info and package_info. On desktop, caching images isn't so important, so I could use the normal image widget on desktop. Downloading songs isn't so important on desktop, which would remove the need for file_picker too. permission_handler won't be needed on desktop (it might on macOS, but this issue is about Linux). Of course, this still means that the app won't work on desktop in its current state, unless you want a music player that doesn't play music. The audio packages are actually supported on macOS, so I might work on some desktop stuff for a potential macOS release.

GabMus commented 3 years ago

As I mentioned in the PR, I'm not a dart/Flutter developer, but maybe one could re-implement those interfaces to work on Linux? Or possibly request Linux support for the original libraries?

jmshrv commented 3 years ago

Windows/Linux support is being worked on for just_audio. The issue can be viewed at https://github.com/ryanheise/just_audio/issues/103. They're working on using VLC for the backend. For audio_service, a "default audio service" was added since Desktop doesn't rely on platform stuff for background playback (https://github.com/ryanheise/audio_service/issues/609/https://github.com/ryanheise/audio_service/pull/632). audio_session may not be required, since that package is meant for configuring the audio player for pausing during calls and stuff.

I might have a look at contributing to the just_audio issue, and I might look into adding MPRIS (and whatever Windows uses) support to audio_service, since the default implementation doesn't really do anything special. No promises though :p

GabMus commented 3 years ago

Any work is highly appreciated! Besides if someone else wants to jump in and contribute, this is already a start :)

jmshrv commented 3 years ago

device_info and package_info could be replaced by the "plus" packages that both have desktop support. https://plus.fluttercommunity.dev/

jmshrv commented 3 years ago

Since everything but flutter_downloader worked on macOS, I tried a macOS version. It technically works, but I've basically just commented out everything related to downloading, which makes the app a bit janky. There are some other issues, such as the settings stuff not loading properly and the progress bar not working. I've pushed the changes to the macos branch if any macOS users want to try messing about with it themselves (not recommended). I'd still like a proper desktop release in the future.

Screenshot 2021-06-01 at 18 16 18

mbnoimi commented 3 years ago

Did you put a deadline for releasing Finamp desktop client? I think Flutter for desktop is somehow mature now

jmshrv commented 3 years ago

It won't be a thing by next release, but maybe the release after. There are three major things that I would have to do:

  1. Add desktop support to just_audio. This shouldn't be too hard since it'll just be a wrapper around dart_vlc.
  2. Create a new download plugin. flutter_downloader is basically entirely native code, so adding desktop support to that would be difficult. Also, flutter_download is a bit buggy with things like download callbacks (this is why download indicators are jank). I'll probably make the plugin in Dart instead of native code for better compatibility.
  3. Make the UI desktop-friendly. The current phone layout won't look right on a big display, so I'd need to mess around with the UI. This would also bring improvements to Finamp on tablets.
mbnoimi commented 3 years ago

It won't be a thing by next release,

I'm really glad to hear that from you and I wish to see the package in the next release. Thanks a lot

jmshrv commented 3 years ago

just_audio just got Windows and Linux support 👀

jmshrv commented 2 years ago

Posting an update since this issue hasn't had one for a bit:

The Windows/Linux package I mentioned above has been discontinued as it wasn't production ready and the Linux implementation wasn't very good - it created a webview to play the audio in an <audio> tag. There have been some recent developments in https://github.com/ryanheise/just_audio/issues/332 with a proper win32-based package for Windows and an mpv-based package for Linux. The mpv package is a bit early on still but it looks very promising and I personally really like mpv so I have no objection using it.

This all means that I can effectively cross of the GStreamer-based package I was going to make (referenced here). Once I've created the new download package (#213), I will be able to make an initial desktop release. From there, I will create a proper desktop UI, which has the added benefit of improving Finamp on tablets.

Fale commented 2 years ago

Very nice to know :-).

Since that part is going to be revamped, it would be nice if - when the Linux Desktop arrives - a Linux Mobile is also provided, which is basically Linux Desktop with the UX of Android/mobile

jmshrv commented 2 years ago

The UI will be adaptive so it should show the mobile form factor on mobile displays

jmshrv commented 2 years ago

Just leaving this here for myself: Flutter sort of supports Linux ARM targets but it needs to be run from a Linux ARM host. https://github.com/flutter/flutter/issues/60678

jmshrv commented 2 years ago

ARM support should be doable, setup was basically the same as x86 (this is running on Asahi Linux)

Screenshot from 2022-06-14 12-35-27

trymeouteh commented 2 years ago

Please release this for Windows and MacOS as well.

For Linux, I would prefer it to be release as the following package types...

AUR Pacstall Flatpak

jmshrv commented 2 years ago

Desktop support will likely come on all platforms at once, it'll just take a while. I should be able to publish on all of those package managers, and I'll also provide a deb, rpm, and a tar.gz of the build for other distros.

Gecked-Deck commented 1 year ago

Any update on this? Just trying out jellyfin for the first time and would love finamp on desktop.

jmshrv commented 1 year ago

The main thing that needs to get implemented is #213, as that is needed for desktop.

I could just rip out downloads for desktop, but that would be an annoyingly involved process (in hindsight, I should have made it more easy to enable/disable downloads).

baarkerlounger commented 1 year ago

Ripping out or disabling downloads would also make it less useful for mobile linux.

Gecked-Deck commented 1 year ago

Well, for now, I'd love to have Finamp on desktop even without downloads. Downloading being implemeted in the future would be awesome (Especially for Linux Mobile, as mentioned) but I can live without it. Your call, of course, just glad to see there's an effort to get it on desktop at all

pztrn commented 1 year ago

Even without downloads, desktop version of Finamp will be very useful. I don't need downloads on my laptop because 99% of time I have working internet connection, as many other people too I presume.

jmshrv commented 1 year ago

Yeah its very unlikely that you're on a desktop without internet. There will still be a few things other than downloads that needs to be done for desktop (UI, ensuring audio works well), so I won't get this done now. I've started writing in detail what needs to be done for #213, see the linked document there for info.

NaturalDevCR commented 9 months ago

Hopefully this will see the light, it would be super helpful to have a windows client.

Chaphasilor commented 7 months ago

Okay, so since we have a new download system in the redesign, adding desktop support is feasible now. I've already got Finamp running on Windows (with the occasional crash), and linux support should also be possible now.
If anyone could take a look into adding linux support (mainly packaging as snap/flatpack/appimage is needed), that would be much appreciated. Use the desktop-beta branch as a starting point.

Here are a few resources that might be useful for that:

Functionality wise, everything should work on linux. If it doesn't, please let me know!

baarkerlounger commented 7 months ago

@Chaphasilor I've been testing the desktop-beta branch with a view to helping with flatpak packaging. Downloads work fine but playback does not work for me (Debian Testing):

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method success on channel vibrate)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332)
<asynchronous suspension>
Chaphasilor commented 7 months ago

Oh, interesting! It seems like the issue isn't playback itself, but rather the vibration feedback when clicking a button. There should be playback options that don't yet give haptic feedback, like tapping a song in the song list to start an instant mix. Can you try if it works like that? When playing/pausing, don't use the now playing bar at the bottom, go to the player screen and pause from there to avoid vibration.
If it works like that, we could simply add additional checks before trying to vibrate the device to avoid these exceptions.

baarkerlounger commented 7 months ago

@Chaphasilor also doesn't seem to work but for a different reason:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ProcessException: No such file or directory
  Command: mpv --idle --msg-level=all=no,ipc=v --no-video --no-audio-display audio-buffer=1 idle=yes --input-ipc-server=/tmp/MPV_Dart.sock
#0      _ProcessImpl._start (dart:io-patch/process_patch.dart:402)
#1      Process.start (dart:io-patch/process_patch.dart:38)
#2      MPVPlayer._createMPVSubProcess (package:mpv_dart/src/mpv.dart:833)
#3      MPVPlayer.start (package:mpv_dart/src/mpv.dart:962)
<asynchronous suspension>
#4      new JustAudioMPVPlayer.<anonymous closure> (package:just_audio_mpv/src/mpv_player.dart:67)
<asynchronous suspension>
baarkerlounger commented 7 months ago

Started flatpak packaging here: https://github.com/baarkerlounger/flathub/tree/finamp

The main things missing I think are:

Chaphasilor commented 7 months ago

@baarkerlounger do you have mpv installed? It's needed for just_audio_mpv to work: https://pub.dev/packages/just_audio_mpv#installation

Chaphasilor commented 7 months ago

Currently the app seems to require dbus permissions - any idea why that is?

That's probably due to the dependency on just_audio_mpris, which is used for populating the media session on linux (so that the currently playing track is shown in the media center).
Is that a huge issue? 🤔

baarkerlounger commented 7 months ago

Thought I did but after apt installing mpv it does work.

That's probably due to the dependency on just_audio_mpris

Ah ok, I think there might be some special case things for mpris so I'll see how other media players have done it

baarkerlounger commented 7 months ago

Bundling MPV in the flatpak build and running that way gets files "playing" but there's no actual sound output. I notice from the logs:

flutter: Get org.mpris.MediaPlayer2.Player.Volume not implemented
flutter: GetPosition(): 0:00:00.000000
Chaphasilor commented 7 months ago

Hmm, no idea. Seems to be within native code. You could try removing audio_service_mpris and seeing if that helps?

baarkerlounger commented 7 months ago

It looks like it's an issue with the pipewire version in the latest freedesktop runtime. Related issues:

Downgrading to 22.08 for now works. So the flatpak now builds and runs, downloading and playing tracks all works. At this point if you're happy to add a tar.gz of build/linux/x64/release/bundle and the aarch64 bundle to a release here, we could probably put a PR up to add Finamp to Flathub.

2 things I've noticed:

  1. When you quit the player it doesn't kill the MPV process so it continues playing until manually killed (not flatpak specific a regular flutter build does this too)
  2. The flatpak version doesn't maintain login state yet so you need to log in each time - how is that intended to work?
Chaphasilor commented 7 months ago

Okay, that sounds nice!
The initial beta release is right around the corner, so I'd target this for the next release at the earliest. Possibly as an experimental feature, so if there's a way to manually download and install the flatpak I think that would suffice for now.

If the mpv process isn't properly killed upon exit, we should defintely investigate this. Maybe just_audio_mpv can do something about it, or maybe we can intercept a SIGTERM or something.

Regarding the login state, that means that the database is not persisted for some reason. That not only breaks login, but also settings persistance and the whole download system. There are two database files, finamp_db.hive and finamp_db.isar. Is there any specific directory where those need to be placed to keep them across restarts?

baarkerlounger commented 7 months ago

Right got login persisting as well.

That sounds good, I'll wait for that release then. Once a PR is up the builder bot will build installable flatpaks that can be used to review. I've also noted in the app description that will be shown on Flathub that Linux build is "beta".

Chaphasilor commented 7 months ago

Regarding the playback issues, we can probably switch to just_audio_media_kit. That should work better and doesn't seem to have any external dependencies.

Can you confirm that shuffle with the current just_audio_mpv is broken? It seems like neither option does support shuffle properly, but I would like to make sure we're not missing out on a core feature by accident...

baarkerlounger commented 7 months ago

As far as I can tell shuffle works fine currently. One thing that's a little confusing is that most of the player controls like next/previous track etc only show up in the song view, not the overview view (screenshots to show what I mean).

image image

Chaphasilor commented 7 months ago

Interesting. I'm trying to get just_audio_media_kit to work and will see if that also supports shuffle...

The buttons are correct that way, an option to configure them will be introduced in a following update :)

Chaphasilor commented 7 months ago

Okay, got it to work on windows. It does work much better than just_audio_windows (doesn't crash when starting playback), but opening the queue and clicking the "shuffle" icon doesn't change the order of the tracks. You say that is different when using just_audio_mpv? Here's a video of how it looks for me:

https://github.com/jmshrv/finamp/assets/18015147/f6ccf174-26f8-4cd0-b052-6848d7ce1ef4

Edit: pushed the changes, you can go ahead and compare the two versions on your own :)

baarkerlounger commented 7 months ago

Ok yeah both versions behave the same for me (same as in your video), the "shuffle to queue" option appears to work though. I did have to apt install libmpv-dev with this version which the just_audio_mpv version I think did not require but on the plus side with this version closing the application does kill the audio process so that's good.

Couple more things I've noticed:

baarkerlounger commented 7 months ago

I see v0.9.3-beta has been announced now. Would it be possible to add Linux build bundles for x64 and (if possible) aarch64 to the release artifacts?

baarkerlounger commented 7 months ago

Another issue (let me know if it would be better to make separate issues for these rather than using this as a Linux catch all) - it seems when you have a play queue it doesn't actually play through them, it stops after each track. The shuffle and repeat buttons are also missing tooltips.

Chaphasilor commented 7 months ago

Yeah I did notice that too on Windows. It sucks, because it essentially means we cannot use that library. I brought in up in their repo already, but no response yet...

Chaphasilor commented 6 months ago

Do you think we should go back to the old libs, or is there anything we can do about this? I don't have much time to deal with this, but would like to see this the light of day at some point ^^

baarkerlounger commented 6 months ago

@Chaphasilor assuming that's a question for me I don't think I can really answer it. I'm not sure if either lib is likely to fix this (or if the problem is even with them). I think my inclination would be to get a release out on Flathub and then iterate on it. Obviously there will be some bugs still but it's use-able already.

Chaphasilor commented 6 months ago

Do you mean a release with the current libs, where playback stops after a single track? Don't you think that's too much of an issue?

baarkerlounger commented 6 months ago

I did yes, I guess that's up to you really. I don't think I know enough about Flutter dev to help much here but I did notice both of the just_audio libs look like they're not particularly actively developed/supported. Is using raw media_kit maybe an option?

Chaphasilor commented 6 months ago

@baarkerlounger as much trouble we might have with just_audio, it actually does its job really well. Even though it's pretty opinioned, it gives us access to a ton of platform-specific functionality, like Android Auto, that we couldn't get with media kit afaik. It's also super-tightly integrated into the app, and we don't have the resources to rip it out any time soon.

However, I managed to fix the bug with playback stopping after each track. I broke stopping in the process, but that's way less important and there's actually no UI to stop at the moment, so it should be fine.
I pushed my changes to the branch, please try if it's also fixed on linux!