如何保存当前播放歌曲的饼干吗? [英] How to save current playing song in cookie?

查看:245
本文介绍了如何保存当前播放歌曲的饼干吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jPlayer插件。下面是一个例子链接[的jsfiddle]

I am using jPlayer plugin. Here is an example link [ jsfiddle ].

我保存在cookie当前播放曲目编号。浏览器后重新装入开始从从cookie加载的曲目号码播放。这个工作,但问题是,当前曲目结束后,它开始从播放列表的第一轨道玩。我希望它继续到下一首曲目。

I save the current playing track number in a cookie. After a browser reload it starts playing from the track number loaded from the cookie. This works but the problem is, after the current track ends, it starts to play from the first track of the playlist. I want it to continue to the next track.

现状示例:


  • 播放列表有10首歌曲

  • 点击数3首歌曲

  • 的cookie保存的号码3首歌

  • 浏览器重装

  • 开始从播放列表中播放一些歌曲3

  • 3号歌曲结束

  • 开始从1号歌曲播放

  • playlist have 10 songs
  • clicked on number 3 song
  • cookie saved number 3 song
  • browser reload
  • start playing number 3 song from playlist
  • number 3 song ends
  • start playing from number 1 song

期望中的情况:


  • 播放列表有10首歌曲

  • 点击数3首歌曲

  • 的cookie保存的号码3首歌

  • 浏览器重装

  • 开始从播放列表中播放一些歌曲3

  • 3号歌曲结束

  • 开始播放一些歌曲4

  • 4号歌曲结束

  • 开始打5号的歌曲

  • ...

推荐答案

myPlayer.play()预计的整数价值,但是当你从cookie读取你得到一个字符串。因此,要解决你的问题,只是通过 parseInt函数传递值(),就像这样:

myPlayer.play() expects an integer value, but when you read from the cookie you get a string. So to fix your problem, just pass the value through parseInt(), like this:

myPlayer.play(parseInt(playnow));

您会发现,在页面重载,正确的曲目将在播放列表中进行选择,因为它开始播放,它会继续正确下一首曲目。

You will notice that on page reload, the proper track will be selected in the playlist as it starts playing, and it will continue to the next track correctly.

演示: http://jsfiddle.net/alan0xd7/6kx616hr/1/

顺便说一句,我觉得的setInterval 1 (1毫秒)实在是太多了,也许 1000 (1秒)就足够了。

By the way, I think setInterval with 1 (1 millisecond) is too much, maybe 1000 (1 second) is enough.

这篇关于如何保存当前播放歌曲的饼干吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆