question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ios] can play in simulator, but cannot play in device.

See original GitHub issue

here is my audio component’s code, and the this.sound.play is not any output, but this.sound.isLoaded() return true,

import React, {PureComponent, Component, PropTypes} from 'react'
import Sound from 'react-native-sound'
import UrlParse from 'url-parse'
import {
    View,
    TouchableOpacity
} from 'react-native'

Sound.setCategory('Playback');

class Audio extends PureComponent {
    static propTypes = {
        uri: PropTypes.string.isRequired
    };

    static defaultProps = {};

    constructor(props) {
        super(props);

        this.state = {
            loading: false
        }
    }

    componentDidMount() {
    }

    _onPress() {
        const urlInfo = UrlParse(this.props.uri)
        this.sound = new Sound(urlInfo.pathname, urlInfo.origin, error => {
            if (error) {

            } else {
                this.sound.play(success => {
                    if (success) {
                        console.log('successfully finished playing');
                    } else {
                        console.log('playback failed due to audio decoding errors');
                    }
                    this.sound.release();
                });
            }
        })
    }

    render() {
        return this.props.uri ?
            (
                <TouchableOpacity activeOpacity={0.5} onPress={() => this._onPress()}>
                    <View>{this.props.children}</View>
                </TouchableOpacity>
            ) : null
    }
}

export default Audio

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lamjackcommented, Sep 5, 2017

thanks all, it’s fixed.

0reactions
Kamill90commented, Apr 11, 2019

@gvenk documentations is still the same. However, this is not fixing the problem. Any other ideas? I need to use only remote, not local files

Read more comments on GitHub >

github_iconTop Results From Across the Web

Video playing on xcode simulator but not on device
1 Answer 1 ... In your iPhone you have a different file system. You can't use the same paths that you use on...
Read more >
A build only device cannot be used… | Apple Developer Forums
Hi I just started recently. I am trying to run my first application whic is a single view Application iOs. Once the project...
Read more >
Ios – Why doesn't ios system sound play in simulator - iTecNote
It works fine on devices but does not play in the simulator. I have created a test app that does nothing but play...
Read more >
VS 2019 16.9.4 cannot connect to iOS Simulator Xcode 12.5
You could disable the remote simulator (Tools / Options / iOS Settings / uncheck “Remote Simulator to Windows”). When unchecked the simulator will...
Read more >
[Answer]-Why doesn't ios system sound play in simulator?-swift
1- The original file path I was using of "/System/Library/Audio/UISounds/Tone.caf" does not work in the simulator, it is only valid on the device....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found