maxcurzi / tplay

A terminal ASCII media player. View images, gifs, videos, webcam, YouTube, etc.. directly in the terminal as ASCII art.
MIT License
208 stars 13 forks source link

panicked at 'Failed to init MPV builder: VersionMismatch { linked: 65644, loaded: 131072 }', #3

Closed maxcurzi closed 1 year ago

maxcurzi commented 1 year ago

panicked at 'Failed to init MPV builder: VersionMismatch { linked: 65644, loaded: 131072 }'

mpv 0.35.1-dirty Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
built on Fri Apr 21 07:11:25 2023
FFmpeg library versions:
libavutil 58.2.100
libavcodec 60.3.100
libavformat 60.3.100
libswscale 7.1.100
libavfilter 9.3.100
libswresample 4.10.100
FFmpeg version: n6.0

But it works on the following:

mpv 0.34.1 Copyright © 2000-2021 mpv/MPlayer/mplayer2 projects built on UNKNOWN 
FFmpeg library versions: libavutil       56.70.100 
libavcodec      58.134.100 
libavformat     58.76.100 
libswscale      5.9.100 
libavfilter     7.110.100 
libswresample   3.9.100 
FFmpeg version: 4.4.2-0ubuntu0.22.04.1
maxcurzi commented 1 year ago

The error resembles https://github.com/ParadoxSpiral/libmpv-rs/issues/27

It's possible that libmpv-rs needs a new release to support mpv 0.35:

see https://github.com/ParadoxSpiral/libmpv-rs/pull/28

maxcurzi commented 1 year ago

A workaround to this issue is to replace in Cargo.toml

libmpv="2.0.1"

with

libmpv-sirno = "2.0.2-fork.1"

Unfortunately, this is not a permanent solution because:

1) The forked crate will be deleted once libmpv gets updated, and 2) The crate will not work if you have installed mpv 0.34, as the error will then be 'Failed to init MPV builder: VersionMismatch { linked: 131072, loaded: 65645 }' note that linked and loaded versions are reversed wrt the original error

neon-mmd commented 1 year ago

I think my issue #4 is related to this, I guess. But please check out my issue #4 again.

neon-mmd commented 1 year ago

Why don't you use rodio crate and replace it with libmpv? I think it will also be a much better replacement as you will not need to have a dependency on libmpv like If it is not installed on the operating system that will not cause much of an issue.

neon-mmd commented 1 year ago

here is the code of rodio implementation I am planning to put it in your player.rs maybe this helps:

use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use std::sync::Arc;

use rodio::decoder::Decoder;
use rodio::queue::Queue;
use rodio::source::Buffered;
use rodio::{Device, Sink};

use crate::common::errors::MyError;

/// The AudioPlayer struct handles audio playback using the rodio backend.
pub struct AudioPlayer {
    /// The rodio sink responsible for managing the audio playback.
    sink: Sink,
    /// The audio file decoder.
    decoder: Decoder<Buffered<BufReader<File>>>,
}

impl AudioPlayer {
    /// Creates a new AudioPlayer instance.
    ///
    /// # Arguments
    ///
    /// * input_path - The path to the audio file to be played.
    ///
    /// # Returns
    ///
    /// A new AudioPlayer instance.
    pub fn new(input_path: &str) -> Result<Self, MyError> {
        let path = Path::new(input_path);
        let file = File::open(path).map_err(|err| {
            MyError::Audio(format!("Failed to open audio file: {:?}", err))
        })?;
        let reader = BufReader::new(file);
        let decoder = Decoder::new(Buffered::new(reader)).map_err(|err| {
            MyError::Audio(format!("Failed to decode audio file: {:?}", err))
        })?;

        let device = Device::default();
        let sink = Sink::new(&device);
        sink.append(decoder.clone());

        Ok(Self { sink, decoder })
    }

    /// Pauses the audio playback.
    ///
    /// # Returns
    ///
    /// A `Result` indicating success or an `MyError::Audio` error.
    pub fn pause(&mut self) -> Result<(), MyError> {
        self.sink.pause();
        Ok(())
    }

    /// Resumes the audio playback.
    ///
    /// # Returns
    ///
    /// A `Result` indicating success or an `MyError::Audio` error.
    pub fn resume(&mut self) -> Result<(), MyError> {
        self.sink.play();
        Ok(())
    }

    /// Toggles the playback state (play/pause) of the audio.
    ///
    /// # Returns
    ///
    /// A `Result` indicating success or an `MyError::Audio` error.
    pub fn toggle_play(&mut self) -> Result<(), MyError> {
        if self.sink.is_paused() {
            self.resume()
        } else {
            self.pause()
        }
    }

    /// Mutes the audio playback.
    ///
    /// # Returns
    ///
    /// A `Result` indicating success or an `MyError::Audio` error.
    pub fn mute(&mut self) -> Result<(), MyError> {
        self.sink.set_volume(0.0);
        Ok(())
    }

    /// Unmutes the audio playback.
    ///
    /// # Returns
    ///
    /// A `Result` indicating success or an `MyError::Audio` error.
    pub fn unmute(&mut self) -> Result<(), MyError> {
        self.sink.set_volume(1.0);
        Ok(())
    }

    /// Toggles the mute state of the audio.
    ///
    /// # Returns
    ///
    /// A `Result` indicating success or an `MyError::Audio` error.
    pub fn toggle_mute(&mut self) -> Result<(), MyError> {
        if self.sink.volume() == 0.0 {
            self
// continued.....
maxcurzi commented 1 year ago

neon-mmd By any means, if you can make it work reliably with rodio I'll welcome the pull request with open arms.

I had some issues with rodio (don't remember what) and settled for mpv

In the meantime, the temporary "fix" for mpv version select is here https://github.com/maxcurzi/tplay/tree/mpv-select if you want to try it out

neon-mmd commented 1 year ago

Yes, as you mentioned rodio doesn't work so I will have to drop that maybe we will have to find another option other than libmpv in the future and also I will test out mpv-select and I will come back to you in a few moments.

neon-mmd commented 1 year ago

No, It didn't work but I tested the main branch by commenting one for the other as you asked and that worked so I think for the aur packaging I guess I will have to use sed to make it change to other libmpv library (the forked one).

nope_does_not_work

neon-mmd commented 1 year ago

Ok thanks for the effort!! :+1: but I added a way to automatically select the other library during installation of the package from the aur with help of regex substitution but still for the project this seems pretty flaky and hacky option. As far as I know the libmpv project has become unmaintained by the main developer of the crate so I think you can continue maintaining the fork but also i guess a better idea would be to get contributors for the fork as well I think you can ask for help for the fork like on r/rust maybe someone will be willing to contribute and help maintain it :smile: .

neon-mmd commented 1 year ago

Ok now you can go forward and merge the pull request #6.

maxcurzi commented 1 year ago

Ok now you can go forward and merge the pull request #6.

I want to finalize the workaround, and maybe find an alternative to mpv. As of now, the solution is too brittle/hacky to be reliable (especially since it relies on very specific versions, and will break again once mpv 0.36 releases, and so on).

As soon as this is fixed a bit better, let's update the aur package and PR #6 will be good to go!

neon-mmd commented 1 year ago

Ok sure, agreed :+1: lets keep the PR #6 halted for now but when you find an alternative and fix the code then you merge the PR but also to help you out in the finding process I have found some small projects to look and understand and maybe reverse engineer it so that maybe if you understand it you can implement it in your code.

Here are some some simple small audio player project:

  1. https://github.com/DJayalath/blue-music
  2. https://github.com/notryanb/music-player
  3. https://github.com/GuillaumeGomez/rust-music-player
  4. https://github.com/Rodrigodd/audio-engine

Also I found one crate which might help as well though it misses some things but still I thought it might help. here is the link to the crate: https://docs.rs/playback-rs/latest/playback_rs

I hope this helps :smile: .

maxcurzi commented 1 year ago

Ok sure, agreed +1 lets keep the PR #6 halted for now but when you find an alternative and fix the code then you merge the PR but also to help you out in the finding process I have found some small projects to look and understand and maybe reverse engineer it so that maybe if you understand it you can implement it in your code.

Here are some some simple small audio player project:

  1. https://github.com/DJayalath/blue-music
  2. https://github.com/notryanb/music-player
  3. https://github.com/GuillaumeGomez/rust-music-player
  4. https://github.com/Rodrigodd/audio-engine

Also I found one crate which might help as well though it misses some things but still I thought it might help. here is the link to the crate: https://docs.rs/playback-rs/latest/playback_rs

I hope this helps smile .

thanks. I now managed to get rodio working fine, and preserve what worked mpv with feature flags, stay tuned!

neon-mmd commented 1 year ago

Welcome. After reading your commit. I am just wondering why you are keeping libmpv still I guess you can remove it because rodio tends to be independent of libmpv and it will work on all linux distros without fail being cross platform but if you want I can test the rodio implementation on myside so that you can completely eliminate libmpv if you wish so and also once your project's libmpv issue gets resolved you can even go ahead and make it a minor release of your project like v0.3.2 or v0.3.5.

It might sound like I am doing too much things here. I apologize if it feels so. Just that I see a great potential in this project and I want this project to grow :smile: .

Also for a wiki I guess you can view how big projects implement them here is one example of it.

Also one more thing assign this bug to yourself and label it under a bug tag this will allow others who might stumble in future to search through issues easily.

neon-mmd commented 1 year ago

Ok please have a look at #9. Finally, I have resolved the issue :smile: . I hope you like the PR :smile: .

maxcurzi commented 1 year ago

closing this as I think we're good with #9 @neon-mmd I just published a new release 0.4.0. I upped the MINOR version because the change is more than a bug-fix as it alters a fundamental dependency which may impact the end user.

neon-mmd commented 1 year ago

Great work!! keep it up :+1: .