{"_id":"5bec8a15287d1b00426efe22","category":{"_id":"5bec8a15287d1b00426efdcb","version":"5bec8a15287d1b00426efe54","project":"578c4badbd223d2000cc1441","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-08-01T23:04:12.838Z","from_sync":false,"order":8,"slug":"api-reference","title":"API Reference"},"project":"578c4badbd223d2000cc1441","user":"576c22a3808cf02b00d37419","parentDoc":null,"version":{"_id":"5bec8a15287d1b00426efe54","project":"578c4badbd223d2000cc1441","__v":0,"forked_from":"5ba2b5747091250003437507","createdAt":"2018-04-23T20:03:35.726Z","releaseDate":"2018-04-23T20:03:35.726Z","categories":["5bec8a15287d1b00426efdc6","5bec8a15287d1b00426efdc7","5bec8a15287d1b00426efdc8","5bec8a15287d1b00426efdc9","5bec8a15287d1b00426efdca","5bec8a15287d1b00426efdcb","5bec8a15287d1b00426efdcc","5bec8a15287d1b00426efdcd","5bec8a15287d1b00426efdce"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.12.0","version":"2.12.0"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-03-18T01:06:46.249Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":39,"body":"A component that enables the user play and control mono and stereo sound effects. Refer to [Sound](doc:audio) under Develop for more information.\n\n######Example use:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<ViroSound\\n    source={require(\\\"./sound/mysound.mp3\\\")}\\n    onFinish={this.onFinishSound} />\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Props\"\n}\n[/block]\n##Required props\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"PropKey\",\n    \"h-1\": \"PropType\",\n    \"0-1\": \"**PropTypes.oneOfType( [PropTypes.shape( {uri:PropTypes.string} ), PropTypes.number])**\\n\\nThe sound source, either a mono or stereo audio file. Supported extensions include .mp3 and .wav.\\n\\nThis can also be the *key* of a preloaded sound. See ```preloadSounds``` below for more information.\",\n    \"0-0\": \"**source**\"\n  },\n  \"cols\": 2,\n  \"rows\": 1\n}\n[/block]\n##Optional Props\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"**loop**\",\n    \"1-0\": \"**muted**\",\n    \"h-0\": \"PropKey\",\n    \"h-1\": \"PropType\",\n    \"0-1\": \"**PropTypes.bool**\\n\\nSet to true to loop the sound. This is set to false by default.\",\n    \"1-1\": \"**PropTypes.bool**\\n\\nSet to true to mute the sound. This is set to false by default.\",\n    \"3-0\": \"**onFinish**\",\n    \"3-1\": \"**React.PropTypes.func**\\n\\nCallback that is called when the sound is finished playing. This function isn't called at the end of a sound if looping is enabled.\",\n    \"4-0\": \"**paused**\",\n    \"4-1\": \"**PropTypes.bool**\\n\\nSet to true to pause the sound. This is set to false by default.\",\n    \"5-0\": \"**volume**\",\n    \"5-1\": \"**PropTypes.number**\\n\\nA number represented volume from 0 to 1. Max volume is equal to 1. Min volume is equal to 0. This is set to 1 by default.\",\n    \"2-0\": \"**onError**\",\n    \"2-1\": \"**React.PropTypes.func**\\n\\nCallback invoked when the Sound fails to load. The error message is contained in event.nativeEvent.error\"\n  },\n  \"cols\": 2,\n  \"rows\": 6\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Methods\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"seekToTime(timeInSeconds)\",\n    \"0-0\": \"Seek to the given point in the Sound, in seconds.\\n\\n|Parameter|Description|\\n|---|---|\\n|timeInSeconds |The seek position in seconds.|\"\n  },\n  \"cols\": 1,\n  \"rows\": 1\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Methods\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"seekToTime(timeInSeconds)\",\n    \"0-0\": \"Seek to the given point in the Sound, in seconds.\\n\\n|Parameter|Description|\\n|---|---|\\n|timeInSeconds |The seek position in seconds.|\"\n  },\n  \"cols\": 1,\n  \"rows\": 1\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Static Methods\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"static preloadSounds(soundMap:{[key:string]: string)\",\n    \"0-0\": \"Given a map of keys and links to their corresponding sound data, Viro will prefetch each sound and store it locally for quick access, asynchronously. You can then play these sounds later by providing the key in the sound's ```source``` attribute. We currently only support external urls (web-based).\\n\\nExample showing the preloading of two sounds:\\n```\\nViroSound.preloadSounds({\\n  \\\"cube_sound\\\" : resolveAssetSource(require(\\\"../res/metronome.mp3\\\")),\\n  \\\"cube_sound_2\\\" : \\\"http://www.kozco.com/tech/32.mp3\\\"),\\n});\\n```\"\n  },\n  \"cols\": 1,\n  \"rows\": 1\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"static unloadSounds(soundKeys: [string])\",\n    \"0-0\": \"Given sound keys, will delete the local prefetched copy of sound data from the application's internal directory. \\n\\n```\\nViroSound.unloadSounds([\\n        \\\"cube_sound\\\",\\n      ]);\\n```\"\n  },\n  \"cols\": 1,\n  \"rows\": 1\n}\n[/block]","excerpt":"","slug":"virosounds","type":"basic","title":"ViroSound"}
A component that enables the user play and control mono and stereo sound effects. Refer to [Sound](doc:audio) under Develop for more information. ######Example use: [block:code] { "codes": [ { "code": "<ViroSound\n source={require(\"./sound/mysound.mp3\")}\n onFinish={this.onFinishSound} />", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Props" } [/block] ##Required props [block:parameters] { "data": { "h-0": "PropKey", "h-1": "PropType", "0-1": "**PropTypes.oneOfType( [PropTypes.shape( {uri:PropTypes.string} ), PropTypes.number])**\n\nThe sound source, either a mono or stereo audio file. Supported extensions include .mp3 and .wav.\n\nThis can also be the *key* of a preloaded sound. See ```preloadSounds``` below for more information.", "0-0": "**source**" }, "cols": 2, "rows": 1 } [/block] ##Optional Props [block:parameters] { "data": { "0-0": "**loop**", "1-0": "**muted**", "h-0": "PropKey", "h-1": "PropType", "0-1": "**PropTypes.bool**\n\nSet to true to loop the sound. This is set to false by default.", "1-1": "**PropTypes.bool**\n\nSet to true to mute the sound. This is set to false by default.", "3-0": "**onFinish**", "3-1": "**React.PropTypes.func**\n\nCallback that is called when the sound is finished playing. This function isn't called at the end of a sound if looping is enabled.", "4-0": "**paused**", "4-1": "**PropTypes.bool**\n\nSet to true to pause the sound. This is set to false by default.", "5-0": "**volume**", "5-1": "**PropTypes.number**\n\nA number represented volume from 0 to 1. Max volume is equal to 1. Min volume is equal to 0. This is set to 1 by default.", "2-0": "**onError**", "2-1": "**React.PropTypes.func**\n\nCallback invoked when the Sound fails to load. The error message is contained in event.nativeEvent.error" }, "cols": 2, "rows": 6 } [/block] [block:api-header] { "title": "Methods" } [/block] [block:parameters] { "data": { "h-0": "seekToTime(timeInSeconds)", "0-0": "Seek to the given point in the Sound, in seconds.\n\n|Parameter|Description|\n|---|---|\n|timeInSeconds |The seek position in seconds.|" }, "cols": 1, "rows": 1 } [/block] [block:api-header] { "title": "Methods" } [/block] [block:parameters] { "data": { "h-0": "seekToTime(timeInSeconds)", "0-0": "Seek to the given point in the Sound, in seconds.\n\n|Parameter|Description|\n|---|---|\n|timeInSeconds |The seek position in seconds.|" }, "cols": 1, "rows": 1 } [/block] [block:api-header] { "title": "Static Methods" } [/block] [block:parameters] { "data": { "h-0": "static preloadSounds(soundMap:{[key:string]: string)", "0-0": "Given a map of keys and links to their corresponding sound data, Viro will prefetch each sound and store it locally for quick access, asynchronously. You can then play these sounds later by providing the key in the sound's ```source``` attribute. We currently only support external urls (web-based).\n\nExample showing the preloading of two sounds:\n```\nViroSound.preloadSounds({\n \"cube_sound\" : resolveAssetSource(require(\"../res/metronome.mp3\")),\n \"cube_sound_2\" : \"http://www.kozco.com/tech/32.mp3\"),\n});\n```" }, "cols": 1, "rows": 1 } [/block] [block:parameters] { "data": { "h-0": "static unloadSounds(soundKeys: [string])", "0-0": "Given sound keys, will delete the local prefetched copy of sound data from the application's internal directory. \n\n```\nViroSound.unloadSounds([\n \"cube_sound\",\n ]);\n```" }, "cols": 1, "rows": 1 } [/block]