Coder Social home page Coder Social logo

Comments (3)

ukasz123 avatar ukasz123 commented on July 29, 2024

@johnareid54 I don't understand. Have you created your Soundpool instance with StreamType.music?
I assume you want to control which audio output your app should use. Is that what you need?

How can I test the problem you've described?

from soundpool.

johnareid54 avatar johnareid54 commented on July 29, 2024

I agree it is a strange problem. It looks similar to the issue Sounds don't play on iOS physical device #28 It was apparently using ringer volume,

My code is very simple but works very well! I just have to find a way to make it uses the media audio on both Android and IOS.

`import 'dart:async';
import 'package:soundpool/soundpool.dart';
import 'package:flutter/services.dart';

class SoundAudio {
  Soundpool _soundpool;
  bool loop = false;
  int _correct;
  int _wrong;
  int _word;
  Timer _timer;

  Future<void> load() async {
    _soundpool = Soundpool(streamType: StreamType.notification);
    var asset = await rootBundle.load("assets/audio/right.mp3");
    _correct = await _soundpool.load(asset);
    asset = await rootBundle.load("assets/audio/wrong.mp3");
    _wrong = await _soundpool.load(asset);
  }

  Future<void> correct() async {
    _soundpool.stop(_word);
    _timer?.cancel();
    loop = false;
    await _soundpool.play(_correct);
  }

  Future<void> wrong() async {
    await _soundpool.play(_wrong);
  }

  Future<bool> loadWord(int file) async {
    _timer?.cancel();
    loop = false;
    String subfolder = "0";
    if (file > 99) subfolder = file.toString().substring(0, 1);
    var asset = await rootBundle.load("assets/words/$subfolder/$file.mp3");
    _word = await _soundpool.load(asset);
    return true;
  }

  Future<void> word() async {
    await _soundpool.play(_word);
  }

  Future<void> correctword() async {
    await _soundpool.play(_correct);
    await _soundpool.play(_word);
  }

  Future<void> loadPlay(int file) async {
    await loadWord(file);
    repeat(3);
  }

  void repeat(int seconds) {
    loop = false;
    Future.delayed(Duration(seconds: 1), () {
      loop = true;
      word();
      _timer = Timer.periodic(Duration(seconds: seconds), (timer) {
        word();
      });
    });
  }

  stop() {
    _soundpool.stop(_word);
    _timer?.cancel();
  }

  Future<void> test() async {
    var asset = await rootBundle.load("assets/audio/190.mp3");
    await _soundpool.loadAndPlay(asset);
  }

  SoundAudio() {
    load();
  }

  void dispose() {
    _soundpool.dispose();
    _timer?.cancel();
  }
}

`

from soundpool.

johnareid54 avatar johnareid54 commented on July 29, 2024

I found the solution to this issue - the channel is controlled by this line--
_soundpool = Soundpool(streamType: StreamType.notification);
Instead of StreamType.notification) change it to StreamType.music.

from soundpool.

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.