Playing sound on device
See original GitHub issueI can get my sounds and the demo app sounds to work on the ios simulator but when I build to my phone on both apps I get no sound. No errors, the app recognizes the mp3 file because I get the length of the mp3 just fine with getDuration()
, here is some of the code, what am I missing?
class MusicPlayer extends Component {
constructor() {
super();
this.playSong = this.playSong.bind(this);
this.pauseSong = this.pauseSong.bind(this);
this.changeVolume = this.changeVolume.bind(this);
this.backPress = this.backPress.bind(this);
this.tick = this.tick.bind(this);
this.state = {
volume: .5,
isPlaying: false,
songLength: 0,
currentTime: 0,
interval: null,
error: null
}
}
componentWillMount() {
var song = new Sound('collide.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
this.setState({
error:error.message
})
} else { // loaded successfully
console.log('duration in seconds: ' + song.getDuration() +
'number of channels: ' + song.getNumberOfChannels());
this.setState({
volume: .5,
song: song,
isPlaying: false,
songLength: song.getDuration(),
currentTime: 0,
interval: null,
error: null
})
}
});
}
playSong() {
this.state.song.play();
this.setState({
isPlaying: true,
interval: setInterval(this.tick, 1000)
})
}
pauseSong() {
this.state.song.pause();
this.setState({
isPlaying: false,
interval: clearInterval(this.state.interval)
})
}
tick() {
this.state.song.getCurrentTime((seconds) => {
this.setState({
currentTime: seconds
})
})
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Play a sound on a device with Find Devices on iCloud.com
Play a sound on your iPhone, iPad, iPod touch, Mac, or Apple Watch ... In Find Devices on iCloud.com, click All Devices, then...
Read more >How To Play Sounds on 2 Devices in Windows - Alphr
1. Make sure that your external devices are connected to your computer. 2. Open “Settings,” then click on “System.” 3. Click on the...
Read more >Play Android Audio on Google Nest or Home devices
Play popular music, playlists, podcasts, and more from your Android device to Google Nest or Home speakers or displays. This is also known...
Read more >Fix sound or audio problems in Windows - Microsoft Support
Select Hardware and Sound from the Control Panel, and then select Sound. On the Playback tab, select and hold (or right-click) Default Device,...
Read more >Play a sound - iCloud Help
In the device's Info window, click Play Sound. Play Sound button in the device's Info window. If the device is online, the sound...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@boblad, take solace in knowing that you aren’t the only one feeling stupid. Thanks for your prompt reply, it fixed my issue!
@Frosty92 I felt really stupid when I figured out my issue, Even if your sound is all up on Ios but your sound switch on the side or your phone is off it wont play. I think there is a method in the docs that overrides this though.
On Wed, May 25, 2016 at 3:16 PM, Hamza Hassan notifications@github.com wrote: