Giter Site home page Giter Site logo

Comments (30)

ryanheise avatar ryanheise commented on July 23, 2024 1

Thanks, I'll look at what exoplayer does.

I don't like position as a parameter name for this method because it could easily be confused for a seek position, given that both the seek and until positions could conceivably be added to this method in the future.

An alternative could be to remove this parameter and have a separate method to set this position. Then the parameter itself could be named position.

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

@rohansohonee , I was planning to implement much the same using the low level MediaExtractor and AudioTrack APIs which would give me more flexibility in implementing the features I want.

E.g. this way, I can implement time stretching and also the untilPosition parameter of play which isn't built in to exoplayer. However, I would consider exoplayer if it were easy to extend it in this way. Do you know anything of its extensibility framework and how one would go about plugging this feature in?

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

I am not clear about the untilPosition parameter of play ?
Can you explain what untilPosition does?

You can customize exoplayer

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

https://pub.dev/documentation/just_audio/latest/just_audio/AudioPlayer/play.html

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

Hmm, I didn't actually document it well, there, either! Basically, it will play until the given position, then pause.

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

By the way, are there specific features that you would like exposed in the flutter API?

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

If you can expose Exoplayer features in flutter API that would be awesome.

IMPORTANT
Please see this ryanheise/audio_service#114

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

@rohansohonee I am not going to add all of exoplayer's features in just_audio, as it comes with a lot of baggage that is not needed. Can you list specific features you would like to use?

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

Gapless playback and Normalize volume if possible.

Also have you seen the memory leak report?
ryanheise/audio_service#114

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

If it's just those two features (in addition to the two already mentioned up the top), I may just implement them myself without bringing in exoplayer, but I'll keep the exoplayer option in mind.

(Yes, I have seen your issue on audio_service.)

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

I've just implemented time stretching and untilPosition on the iOS side (edit: sorry, I meant "Android" side). Gapless playback is possible by creating multiple instances and preparing the next instance for playback in advance.

I haven't looked at normalising the volume. How exactly should this behave?

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

Merry Christmas @ryanheise

I haven't looked at normalising the volume. How exactly should this behave?

  • Normalizing volume should keep a consistent volume between tracks. If it is possible to implement this then do so.

Gapless playback is possible by creating multiple instances and preparing the next instance for playback in advance.

  • I do this using the audioplayers plugin. The issue is it glitches the sound when playing the prepared instance. The reason for the glitch is that it uses MediaPlayer on android. Are you using MediaPlayer or AudioTrack??

I've just implemented time stretching and untilPosition on the iOS side.

  • Is this available for android as well?

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

I'm using AudioTrack. Let me know how it goes with gapless playback. If it still glitches, I'll look at building this feature into the plugin by using a single, continuous AudioTrack between files.

I should correct my earlier comment: I implemented untilPosition and time stretching on the "Android" side. I haven't yet done it on the iOS side.

Thanks for clarifying the normalised volume. I think it's a good idea, but it would require some time consuming and CPU intensive lookahead to determine the average energy of an audio file. If you have any references to articles etc. on how it could be done, that would be welcome.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

I just know that exoplayer has the feature for normalising volume.

also rename untilPosition to just position.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024
  • It seems we can never start playback of audio as you have added a condition as follows:

Plays the currently loaded media from the current position. It is legal to invoke this method only from one of the following states:
[AudioPlaybackState.stopped]
[AudioPlaybackState.paused]

  • This means we can never start the initial playback. We never are in either stopped or paused.

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

After setUrl you should be in the stopped state.

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

One more thing which is not yet documented is that the future returned by play will complete when playback completes.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

I created two instances of AudioPlayer().
If i stop player A it also stops B??
Multiple audio players should be possible to run.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

Also the glitch occurs when calling play of player B while player A is running.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

There is no AudioPlaybackState.completed state.
Also the onplayercompletion stream listener should be added.
Gapless playback not working since glitch is present when swapping previous song with next song.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

Reason for gapless audio playback is because i want to cross fade between two tracks i.e fade out volume of current song while simultaneously fading in the next song, thus performing smooth transition.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

Hi @ryanheise

I went through the android code and these are the changes you can make:

  1. Don't use MediaExtractor for decoding audio, but instead use FFmpeg for decoding the audio file.
    here is an article explaining the huge performance improvement.
    https://medium.com/@donturner/using-ffmpeg-for-faster-audio-decoding-967894e94e71
  2. Also you should really look into just using ExoPlayer as you will not have to make all these things from scratch.
  3. FFmpeg is also cross platform which is very useful for flutter.

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

Hi @rohansohonee

I did look into using ExoPlayer, but I did not see a way to implement untilPosition (which I need) without basically rewriting that whole part of the implementation anyway, and even then I would not be able to plug this into their interface because they designed their API without the forethought of having a feature like this. In the end, I am familiar enough with the low level Android APIs that it was going to be easier to just use those APIs. I understand that ExoPlayer is not so much of a "feature request" as it is an "implementation suggestion", and I'll still keep it on the table in the future, but for now it was much quicker for me to implement untilPosition this way. For now, I will just focus on features.

FFmpeg sounds good in theory but its license may get in the way of most developers of commercial apps actually being able to use it. See for example: https://trac.ffmpeg.org/ticket/1229 . If it weren't such an issue, I would definitely consider it. After all, FFmpeg would also result in lower battery usage. But in my opinion any cost of battery usage will be minor compared to battery used by the screen, and general performance is not going to be noticeable for the use case of just playing an audio file. I think the performance of FFmpeg would be useful when decoding a whole file in one go for analysis, e.g. to compute the average energy in order to normalise volume, but given the licensing issue, I would prefer to find a cheaper approach that can be done on the fly.

Speaking of normalisation, I wasn't able to find this feature in ExoPlayer. I found an issue on it, but it was closed without resolution: google/ExoPlayer#4541 . If you have any information on where it is implemented, I can take a look.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

How is exoplayer using ffmpeg extensions then???

How do i perform gapless playback and Crossfade using your package?? I have tried two instances, where i am starting player B and stopping & immediately starting player A and then stopping player B to try gapless playback.
But there is always a glitch in audio. The transition is never smooth.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

https://github.com/google/ExoPlayer/tree/release-v2/extensions/ffmpeg

The source code of ffmpeg extensions used in exoplayer.
Every android music app on play store uses exoplayer. They don't seem to be running into license issue??

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

It is mentioned on that page:

License note

Please note that whilst the code in this repository is licensed under
[Apache 2.0][], using this extension also requires building and including one or
more external libraries as described below. These are licensed separately.

FFmpeg itself is licensed under the LGPL.

However, this is just an optional extension and not everyone using ExoPlayer will be using FFmpeg.

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

So how do apps that are using it achieve it??

from just_audio.

ryanheise avatar ryanheise commented on July 23, 2024

The general consensus online is that you should seek legal advice :-)

from just_audio.

rohansohonee avatar rohansohonee commented on July 23, 2024

can you help with this issue if possible:

How do i perform gapless playback and Crossfade using your package?? I have tried two instances, where i am starting player B and stopping & immediately starting player A and then stopping player B to try gapless playback.
But there is always a glitch in audio. The transition is never smooth.

from just_audio.

github-actions avatar github-actions commented on July 23, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

from just_audio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.