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

Audio doesn't play when play function is inside other callbacks (using bleno library) #41

Open
federicomazzini opened this issue Apr 12, 2020 · 0 comments

Comments

@federicomazzini
Copy link

Good afternoon and thank you for your work.

I'm trying to play an audio file when I receive a value from a bluetooth characteristic on a Raspberry Pi. I'm using bleno for bluetooth.
I can play files following the example, but I cannot play them when inside the bluetooth loop and I don't know how to debug that. I'm not sure if it's because of being inside another process or because of something related with the event loop, or maybe because of the path of the file, but it does not throw an error. Also I'm using a setTimeout function with a number coming from bluetooth, but I've done that before without any issues.

This is the file in which I try to play an mp3 file:

const player = require('play-sound')();
module.exports.squeduleSound = function (seconds) {
    setTimeout(function() {
	playSound();
    }, seconds*1000);
};

function playSound() {
        console.log('Playing sound');
        player.play('./sound.mp3', (err) => {
                if (err) console.log('Could not play sound: ${err}');
	});
}

And this is the bluetooth callback, the onWriteRequest method is part of the bleno library:

var soundSqueduler = require('../audioPlayer/audioScheduler');
WriteTimeCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {
	this._value = data;
    	var seconds =  this._value.toString('utf8');
    	console.log('CustomCharacteristic - onWriteRequest: value = ' + seconds);
    	soundSqueduler.squeduleSound(seconds);
	callback(this.RESULT_SUCCESS);
};

I'm using node version: 8.11.1. (I can't use a newer one because of bleno. But I've done this in the past with this version.)
bleno version: 0.5.0
play-sound: 1.1.3

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant