Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

react native sound typescript not working

$
0
0
import Sound from 'react-native-sound';import Tab from '../router/bottomTabNav';import {Button} from 'react-native';import mp3 from './Sound5/5.mp3';interface mp3 {  mp3: mp3;}function AudioClock() {Sound.setCategory('Playback');const audioFile = new Sound((mp3), (error) => {  if (error) {    console.log('failed to load the sound', error);    return;  }  // loaded successfully  console.log('duration in seconds: '+ audioFile.getDuration() +'number of channels: '+ audioFile.getNumberOfChannels());  audioFile.setVolume(1);audioFile.setPan(1); audioFile.play((success) => {    if (success) {      console.log('successfully finished playing');    } else {      console.log('playback failed due to audio decoding errors');    }  });});<Button        title="Say time"        onPress={Tab}      />}updated the asset.d.ts and tsconfig.json respectively declare module "*.mp3" {    const value: any;    export default value;  }"include": ["src/*","types/*"

on click of Tab, no sound, if in the beginning i doconst audioFile = new Sound((Sound.mp3), (error) => {

instead of const audioFile = new Sound((mp3), (error) => {there is a mp3 type error. either way i know importing on typescript broken for audio but i thought this would work.

it's such simple functionality but so problematic in typescript it seems. i did leverage this code from an alarm clock function so let me know if anything suspect there, although i do see it as a wider. ts mp3 issue. lmk thanks


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>