import React, {Component} from 'react';

import {
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
  Platform,
} from 'react-native';
const Sound = require('react-native-sound');

const Button = ({title, onPress}) => (
  <TouchableOpacity onPress={onPress}>
    <Text style={styles.button}>{title}</Text>
  </TouchableOpacity>
);

const Header = ({children}) => (<Text style={styles.header}>{children}</Text>);

const Feature = ({title, onPress, description, buttonLabel = "PLAY"}) => (
  <View style={styles.feature}>
    <Header>{title}</Header>
    <Button title={buttonLabel} onPress={onPress}/>
  </View>);

const requireAudio = require('./advertising.mp3');

class MainView extends Component {

  constructor(props) {
    super(props);

    Sound.setCategory('Ambient', true); // true = mixWithOthers

    this.playSoundBundle = () => {
      const s = new Sound('advertising.mp3', Sound.MAIN_BUNDLE, (e) => {
        if (e) {
          console.log('error', e);
        } else {
          s.setSpeed(1);
          console.log('duration', s.getDuration());
          s.play(() => s.release()); // Release when it's done so we're not using up resources
        }
      });
    };

    this.playSoundFromRequire = () => {
      const s = new Sound(requireAudio, (e) => {
        if (e) {
          console.log('error', e);
          return;
        }

        s.play(() => s.release());
      });
    };



  }

  renderiOSOnlyFeatures() {
    return [
      <Feature key="require" title="Audio via 'require' statement" onPress={this.playSoundFromRequire}/>,
    ]
  }

  render() {
    return <View style={styles.container}>
      <Feature title="Main bundle audio" onPress={this.playSoundBundle}/>
      { Platform.OS === 'ios' ? this.renderiOSOnlyFeatures() : null }
    </View>
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
    justifyContent: 'center',
    alignItems: 'center',
  },
  button: {
    fontSize: 20,
    backgroundColor: 'silver',
    padding: 5,
  },
  header: {
    borderBottomWidth: 1,
    borderBottomColor: 'black',
  },
  feature: {
    padding: 20,
    alignSelf: 'stretch',
  }
});

export default MainView;

@@ -1179,16 +1179,570 @@
     %7D;%0A%0A
+    this.playSoundLooped = () =%3E %7B%0A      if (this.state.loopingSound) %7B%0A        return;%0A      %7D%0A      const s = new Sound('advertising.mp3', Sound.MAIN_BUNDLE, (e) =%3E %7B%0A        if (e) %7B%0A          console.log('error', e);%0A        %7D%0A        s.setNumberOfLoops(-1);%0A        s.play();%0A      %7D);%0A      this.setState(%7BloopingSound: s%7D);%0A    %7D;%0A%0A    this.stopSoundLooped = () =%3E %7B%0A      if (!this.state.loopingSound) %7B%0A        return;%0A      %7D%0A%0A      this.state.loopingSound%0A        .stop()%0A        .release();%0A      this.setState(%7BloopingSound: null%7D);%0A    %7D;%0A%0A
     this
@@ -1765,32 +1765,32 @@
 quire = () =%3E %7B%0A
-
       const s = 
@@ -1956,17 +1956,72 @@
     %7D;%0A%0A
-%0A
+    this.state = %7B%0A      loopingSound: undefined,%0A    %7D;
 %0A  %7D%0A%0A  
@@ -2232,16 +2232,16 @@
 ainer%7D%3E%0A
-
       %3CF
@@ -2306,16 +2306,271 @@
 ndle%7D/%3E%0A
+      %7Bthis.state.loopingSound%0A        ? %3CFeature title=%22Main bundle audio (looped)%22 buttonLabel=%7B'STOP'%7D onPress=%7Bthis.stopSoundLooped%7D/%3E%0A        : %3CFeature title=%22Main bundle audio (looped)%22 buttonLabel=%7B'PLAY'%7D onPress=%7Bthis.playSoundLooped%7D/%3E%0A      %7D%0A
       %7B 

Add example to test looping (#5)