Skip to content

Can't play recorded track #35

Open

Description

@mtkgeek

i keep getting the Failed assertion: line 309 pos 12: 'track != null': is not true. error whenever i try to play my recorded track using Quickplay.fromTrack().
Here's a snippet of my code

String recording;
Track track;
Future<void> startRecording() async {
    recording = Track.tempFile(WellKnownMediaFormats.adtsAac);
    track =
        Track.fromFile(recording, mediaFormat: WellKnownMediaFormats.adtsAac);

    recorder.onRequestPermissions = (_) => requestPermissions();
    try { 
      await recorder.record(track);
      print(recorder.isRecording);
} catch(e)
 {
print(e);     
    }
}

After recording with the above method then i call the method below

Future<void> stopRecording() async {
    try {
      print(recorder.isRecording);
    
      await recorder.stop();
      print(track);
    } catch (error) {
      print(error);
    } finally { 
      QuickPlay.fromTrack(track);    
    }
  }

Note: All methods are in the same class.

Activity

  1. added
    help wanted
    on Aug 30, 2020
  2. changed the title [-][HELP][/-] [+]Can't play recorded track[/+] on Aug 30, 2020
  3. bsutton commented on Sep 2, 2020

    @bsutton
    Owner

    At the very least the finally block is a problem as it will execute even if the exception is thrown

  4. mtkgeek commented on Sep 2, 2020

    @mtkgeek
    Author

    Removing the finally block doesn't solve the issue. The problem ultimately is why is track null?

  5. bsutton commented on Sep 2, 2020

    @bsutton
    Owner
  6. bsutton commented on Sep 16, 2020

    @bsutton
    Owner

    I have a theory the problem is in QuickPlay._play

    try changing it to the following (note the extra awaits)

     Future<void> _play(double volume) async {
        await _player.setVolume(volume);
        await _player.audioFocus(AudioFocus.hushOthersWithResume);
        _player.onStopped = ({wasUser}) {
          _player.release();
          if (_onStopped != null) _onStopped();
        };
        return _player.play(_track);
      }

    It feels like its a race condition at the android level.
    The awaits should hopefully fix this.

    We are a week or so from being able to push a new release as we are in the middle of converting the objective-c code to swift.

  7. bsutton commented on Sep 17, 2020

    @bsutton
    Owner

    I've pushed the above code to git.
    If you could give it a test that would be helpful.

  8. bsutton commented on Sep 17, 2020

    @bsutton
    Owner
  9. added a commit that references this issue on Sep 22, 2020
  10. carlos-labrador commented on Dec 21, 2020

    @carlos-labrador

    Hi @bsutton ,
    It's still not working, and the issue is related to named constructors.

    So, QuickPlay.fromTrack constructor is calling QuickPlay._internal constructor, and this is instantiated for second time in the QuickPlay class without "Track" attribute.

    Quick fix would be to only pass Track object into QuickPlay._internal constructor.

    You can try the code below to verify my solution.

    void main() {
      QuickPlay.fromTrack("mytrack");
    }
    
    class QuickPlay {
      String _track;
      QuickPlay.fromTrack(
        this._track, {
        double volume,
        bool withShadeUI = false,
      }) {
        print("internal $_track $volume $withShadeUI");
        
       
        QuickPlay.internal(this._track, volume,withShadeUI);
      }
    
      QuickPlay.internal(this._track, double volume, bool withShadeUI) {
         if (withShadeUI) {
          print('withShadeUI');
        } else {
          print("withShadeUI NO");
        }
        _play(volume);
      }
    
      Future<void> _play(double volume) async {
        print('playing  $_track $volume');
      }
    }
    
    

    Cheers mate.
    Greetings to Melbourne.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions