我想在 React Native 中播放声音。
我曾尝试在zmxv/react-native-sound 中阅读这里,但作为像我这样的初学者,该文档让我很困惑如何在 React Native 代码中应用它。
在我尝试使用此方法在事件上制作本机播放声音并制作如下代码之前:
import React, { Component } from 'react'
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native'
const Sound = require('react-native-sound')
export default class MovieList extends Component {
handlePress() {
// Play some sound here
let hello = new Sound('motorcycle.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log(error)
}
})
hello.play((success) => {
if (!success) {
console.log('Sound did not play')
}
})
}
render() {
const { …Run Code Online (Sandbox Code Playgroud) 我正在使用React Native 和 React Native Sound创建音频播放器,但现在我面临一些问题。我的问题是我想停止当前播放的歌曲并播放下一首歌曲,但我不知道该怎么做。这是我的代码:
我正在使用 React、React Native 和 React Native Sound。
export default class PlaySound extends Component {
constructor(props) {
super(props);
this.state = {
stop: false,
playing: false
};
this.stopTrack = () => {
if(!this.state.playing){
return;
}
this.setState({ stop: false });
this.state.playing.stop();
}
}
renderTrackButton(track){
if(this.state.stop){
return (
<Button danger onPress={() => this.stopTrack()}>
<Text>Stop</Text>
</Button>
);
}else{
return (
<Button onPress={() => this.playTrack(track)}>
<Text>Play</Text>
</Button>
);
}
}
playTrack = (track) => {
const callback =(error, …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 expo 版本实现一个 React Native 流应用程序,但遇到了一些困难。请随意回答任何问题或仅回答一个问题以及您选择的任何其他问题。
1) 在声音播放时实现进度条。为此,我需要获取歌曲的持续时间,然后使用 Math.Floor 来计算进度条,但我目前无法获取当前播放曲目的持续时间。关于如何使用声音对象或视频组件来执行此操作的任何想法都将非常有用。
2)我需要能够从我的应用程序播放背景声音,并且根据一些研究,世博版本似乎不可能。这方面有什么黑客吗???
3)如何使用Audio组件判断当前播放的曲目是否已经结束?
4)我想要一种情况,当我的设备播放声音时,我可以停止设备中的任何其他声音。关于如何做到这一点有任何想法吗?
5) 对我使用 React Native 的流媒体应用程序有什么建议
process audio-streaming react-native react-native-sound expo
我是反应原生新手,我正在构建一个应用程序来在按下按钮时播放声音,但我无法实现这一点,是因为我的代码中存在错误吗?另请建议播放声音的解决方案并提出更正建议
这是我的代码:
import React, { Component } from 'react';
import { StatusBar, Dimensions, Image, TouchableWithoutFeedback, Animated } from 'react-native';
import { Actions } from 'react-native-router-flux';
import Sound from 'react-native-sound';
const a = require('./Images/landing-bnt1-on.png');
const b = require('./Images/landing-bnt1.png');
const c = require('./Images/landing-bnt2-on.png');
const d = require('./Images/landing-bnt2.png');
const btnSound = new Sound('./Sounds/btn_sound.mp3');
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
class MainScreen extends Component {
state = {
computerPressed: false,
teamPressed: false
}
componentWillMount() {
this.slide1 = new Animated.Value(0);
this.slide2 = new …Run Code Online (Sandbox Code Playgroud)我正在使用 Lottie 命令式 API 来显示循环动画。除了使用React Native Sound 的组件外,命令式 API 在我的所有组件上都运行良好。我认为问题是两个库都是用.play(). 这可能吗?
洛蒂:this.animation.play();
反应原生声音:this.sound.play()
调用 Lottie 方法后,我收到错误消息:
无法读取未定义的属性“播放”
有任何想法吗?
提前致谢。