Code Monkey home page Code Monkey logo

Comments (5)

mmartinalo avatar mmartinalo commented on July 21, 2024 1

Hello @ryanheise ,

I was reading in-depth the documentation and I realized that AVAudioSession playAndRecord category solve my problems:

  • plays audio through earpiece
  • locks the screen

Both for android and ios the code would be something like

    final session = await AudioSession.instance;
    final AndroidAudioAttributes currentAndroidAttributes = session.configuration.androidAudioAttributes;
    await session.configure(
      session.configuration.copyWith(
        androidAudioAttributes: AndroidAudioAttributes(
          usage: AndroidAudioUsage.voiceCommunication,
          flags: currentAndroidAttributes.flags,
          contentType: currentAndroidAttributes.contentType,
        ),
        avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
      ),
    );

I think it would be interesting to encapsulate a similar logic in a public function in the AudioPlayer.

Thanks for the support!

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

Hi @mmartinalo , the eventual goal is to implement all of the AVAudioSession API but I started with just the features that I personally needed. If you take a look at the source documentation for Apple's AVAudioSession , perhaps you can identify which features you need, then you can let me know and I can add those features next.

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

Glad you found a solution. I'd rather have a clear separation of concerns between these two plugins so that audio_session is responsible for switching between devices or detecting when a switch occurs, while just_audio doesn't need to know.

Interestingly, the name "just" audio actually stemmed from a goal to build an audio plugin that didn't take on any other responsibilities besides the audio signal itself, while different plugins could handle settings for the hardware devices, etc.

from audio_session.

mrtnetwork avatar mrtnetwork commented on July 21, 2024

Hello @ryanheise ,

I was reading in-depth the documentation and I realized that AVAudioSession playAndRecord category solve my problems:

  • plays audio through earpiece
  • locks the screen

Both for android and ios the code would be something like

    final session = await AudioSession.instance;
    final AndroidAudioAttributes currentAndroidAttributes = session.configuration.androidAudioAttributes;
    await session.configure(
      session.configuration.copyWith(
        androidAudioAttributes: AndroidAudioAttributes(
          usage: AndroidAudioUsage.voiceCommunication,
          flags: currentAndroidAttributes.flags,
          contentType: currentAndroidAttributes.contentType,
        ),
        avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
      ),
    );

I think it would be interesting to encapsulate a similar logic in a public function in the AudioPlayer.

Thanks for the support!

thanks , you saved my time :X

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

Would you mind sharing your solution on this issue? #37

The goal of that issue is to provide a convenience method in the AudioSession class to handle this common use case in a platform-independent way (while still keeping the native APIs available for more advanced use cases).

from audio_session.

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.