Soundcloud流,soundmanager2对象在调用play()时从未在Chrome上开始播放
Soundcloud stream, soundmanager2 object never starts playing on Chrome when calling play()
在我的react应用程序中使用SC.stream,我只是尝试播放soundcloud API中的曲目。这是我的代码:
SC.initialize({
client_id: '12xxx' // my client ID
});
//[...]
console.log(this.props.track.trackId); // I get here successfully the trackId from the song I'd like to play
SC.stream('/tracks/'+this.props.track.trackId, function(track){
track.play();
console.log(track); // I successfully get the track object here. playState attribute is on 1
});
不幸的是,这些曲目从未开始播放。控制台上没有错误。
编辑:问题只出在chrome上,它在firefox和safari上完美工作。我现在更困惑了。
编辑2:它似乎链接到HTML5播放器不在Chrome上工作:当你在上重新启用flash播放器时chrome://plugins/通过检查"始终允许运行",它可以运行
我不确定当你有track.play()时,从代码中"track"指的是什么。如果它是音频div,那么这应该会有所帮助。
class PlayerCtrlRender extends React.Component {
render() {
let index = this.state.playIndex;
let currentTrack = this.state.randomOn ? this.state.shuffledQueue[index] : this.props.queue[index];
let source = 'http://192.168.0.101:3950/play/' + currentTrack.location;
let title = currentTrack.title;
let progressData = {count: this.state.progressCount * 100, index: this.state.progressIndex * 100};
return (
<div id='PlayerCtrlSty' style={PlayerCtrlSty}>
<div className='FlexBox'>
<div style={timerLeftSty}>{this.state.progressIndex}</div>
<PlayerActions playing={this.state.isPlaying} clickHandler={this.clickHandler}/>
<div style={timerRightSty}>{this.state.progressCount}</div>
</div>
<JProgressBar data={progressData} position='none' />
<div id="title" style={{textAlign: 'center'}}>{title}</div>
<audio
ref="audioDiv"
src={source}
onDurationChange={this.onDurationChange}
onTimeUpdate={this.onTimeUpdate}
onEnded={this.nextSong}
/>
</div>
);
}
}
export default class PlayerCtrl extends PlayerCtrlRender {
constructor() {
super();
this.state = {
playIndex: 0,
queueLength: 1,
isPlaying: false,
progressCount: 0,
progressIndex: 0,
shuffledQueue: [{title: '', location: ''}],
randomOn: false
};
}
componentDidMount = () => {
let queue = knuthShuffle(this.props.queue.slice(0));
this.setState({queueLength: queue.length, shuffledQueue: queue});
this.refs.audioDiv.volume = .1;
}
clickHandler = (buttonid) => {
this.refs.audioDiv.autoplay = false;
switch (buttonid) {
case 'play': this.refs.audioDiv.play(); this.setState({isPlaying: true}); break;
case 'pause': this.refs.audioDiv.pause(); this.setState({isPlaying: false}); break;
case 'back': this.refs.audioDiv.currentTime = 0; break;
case 'next': this.nextSong(); break;
case 'random': this.refs.audioDiv.autoplay = this.state.isPlaying;
this.setState({randomOn: !this.state.randomOn}); break;
}
}
nextSong = () => {
this.refs.audioDiv.autoplay = this.state.isPlaying;
this.refs.audioDiv.currentTime = 0;
let newIndex = this.state.playIndex + 1;
if (newIndex == this.state.queueLength) newIndex = 0;
this.setState({playIndex: newIndex});
}
onDurationChange = () => {
let duration = this.refs.audioDiv.duration;
duration = getTime(Math.floor(duration));
this.setState({progressCount: duration})
this.setState({progressIndex: 0})
}
onTimeUpdate = () => {
let currentTime = this.refs.audioDiv.currentTime;
currentTime = getTime(Math.floor(currentTime));
this.setState({progressIndex: currentTime})
}
}
相关文章:
- Android上的Chrome无法播放来自对象URL的录制音频
- 播放列表在IE和Chrome中无法正确显示
- JavaScript/HTML5音频:在Android Chrome中播放用户通过文件选择器加载的mp3文件
- 停止在Chrome上自动播放嵌入的Javascript歌曲
- javascript播放的声音不适用于chrome for android
- Jwplayer可以'不要在Chrome中播放视频
- 如何了解视频是否在chrome中以全屏模式播放
- 无法使用 Android 版 Chrome 播放 blob 网址视频
- Chrome for iOS 中的 JavaScript 可以播放声音吗?
- Chrome 无法在重复的标签上播放 html5 视频
- 在 Chrome 中播放音频和流式传输问题
- 移动版 Chrome 上的 IFrame 播放器 API
- 如何让Chrome和/或Firefox在Karma测试中播放<音频>元素
- 在chrome中动态添加的音频html无法正常播放,在Firefox中正常工作
- 从Google Chrome浏览器在本地播放器中打开视频URL
- Flowplayer中的MP4视频无法在Windows 7 Chrome中播放
- HTML5视频不会在Chrome和Safari上自动播放
- 播放base64音频文件不会'不适用于最新版本的Chrome(46.0.2490.86米)
- 如何绕过Chrome禁用视频自动播放's在背景选项卡中
- Chrome:播放正在通过fetch/XHR下载的视频