Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't play recorded track #35

Open
mtkgeek opened this issue Aug 30, 2020 · 7 comments
Open

Can't play recorded track #35

mtkgeek opened this issue Aug 30, 2020 · 7 comments
Labels

Comments

@mtkgeek
Copy link

mtkgeek commented Aug 30, 2020

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.

@mtkgeek mtkgeek added the help wanted Extra attention is needed label Aug 30, 2020
@mtkgeek mtkgeek changed the title [HELP] Can't play recorded track Aug 30, 2020
@bsutton
Copy link
Owner

bsutton commented Sep 2, 2020

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

@mtkgeek
Copy link
Author

mtkgeek commented Sep 2, 2020

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

@bsutton
Copy link
Owner

bsutton commented Sep 2, 2020 via email

@bsutton
Copy link
Owner

bsutton commented Sep 16, 2020

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.

@bsutton
Copy link
Owner

bsutton commented Sep 17, 2020

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

@bsutton
Copy link
Owner

bsutton commented Sep 17, 2020 via email

bsutton added a commit that referenced this issue Sep 22, 2020
@carlos-labrador
Copy link

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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants