GithubHelp home page GithubHelp logo

在线音乐如果获取时长 about snow HOT 28 CLOSED

jrfeng avatar jrfeng commented on July 28, 2024
在线音乐如果获取时长

from snow.

Comments (28)

jrfeng avatar jrfeng commented on July 28, 2024

目前时长都必须预先设置,不支持在播放时获取时长,不过我会把这个需求加上的。

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

嗯嗯,尽快吧大佬。我现在是自己读到了。又重置了下,有点low

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

@cowoboy007PlayerService 添加了一个新方法:

protected void onPrepareMusicItem(
    MusicItem musicItem,
    SoundQuality soundQuality,
    AsyncResult<MusicItem> result
)

该方法会在歌曲即将播放前调用,你可以在该方法中对MusicItem 对象进行修改。例如,从服务器获取歌曲的播放时长、播放链接,并使用这些数据更新 MusicItem 对象。

MusicItem 对象的修改可能会被持久化保存到本地,请务必注意这一点。

该方法会在异步线程中执行,因此可以执行各种耗时操作,例如访问网络。

注意:如果你在 onPrepareMusicItem 方法中获取并修改了 MusicItem 的播放链接,但你同时又重写了 PlayerServiceonRetrieveMusicItemUri 方法来获取歌曲的最新播放链接,则在播放歌曲时,会优先使用 onRetrieveMusicItemUri 方法获取到的播放链接。如果你仅仅只需要在播放时获取歌曲的最新播放链接,建议重写 onRetrieveMusicItemUri 方法即可。如果你在 onPrepareMusicItem 已经获取并修改了 MusicItem 的播放链接,则不需要再重写 onRetrieveMusicItemUri 方法。

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

在线链接这个 我复写onRetrieveMusicItemUri这个解决了。主要是mediaplayer如何在prepared后。动态的把时长写入musicItem,同时还本地化

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

可以详细说下你需要 MediaPlayer 的时长的用处吗?

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

服务器给不了我时长。我需要prepare后,把时长给到musicitem。

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

OK, 我看下有没有好的解决方案,如果有的话,我会加上的

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

好的。感谢

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

@cowoboy007 你获取这个 duration 的主要用途是什么?可以详细描述一下使用场景吗?

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

很简单哈。播放页面进度条需要时长对吧。服务器只给我url。我需要播放器内部把时长处理好,并且存储本地化,同时下次获取到了就不用再存储了

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

就是播放器内部去把未设置时长的musicitem 管理起来。不需要创建播放列表的时候必须传

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

你的实时播放进度是使用 PlayerViewModel 还是 LiveProgress 实现的?

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

PlayerViewModel

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

和做个没关系吧。他只有进度。没有duration

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

PlayerViewModel 需要正确的 duration 才能正常工作。

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

在不知道 duration 的情况下,你在创建 MusicItem 对象时把 duration 设置成了什么值?

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

@cowoboy007MusicItem.Builder 添加了一个方法:autoDuration()。你可以在使用 MusicItem.Builder 构建 MusicItem 对象时调用该方法。这将延迟到播放器准备完毕后自动获取 MusicItemduration。调用该方法后,PlayerViewModel 的实时播放进度功能将能够正常工作。

例:

MusicItem song = new MusicItem.Builder()
            .setTitle("title")
            .setArtist("artist")
            .autoDuration()        // 自动获取歌曲的播放时长
            .setUri("url")
            .build();

PS: 因为是新添加的功能,可能会有 BUG,如果遇到了 BUG,欢迎反馈 😄😄😄

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

方法已重命名:delayDuration() -> autoDuration()

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

嗯嗯,试了下。有个问题就是。这个duration 写入到mmkv了吗。感觉下次进来还是0.需要播放才能拿到。理论上第一次拿到后,应该存起来,以后都不需要再拿了。直接读取本地的

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

只会保存当前正在播放的歌曲的 duration

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

已重构睡眠定时器,增加方法:setWaitPlayComplete(boolean)

如果你需要睡眠定时器时间到时,等待当前正在播放的歌曲播放完成后再执行指定动作(例如,暂停播放),则可以调用 PlayerClient#setWaitPlayComplete(boolean) 方法并传入 true

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

大佬如果在后台运行,只保留服务了。我怎么监听进度,我在playservice里面监听progress貌似不起作用

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

是用来做 UI 展示吗?

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

不是。当所有界面全部销毁了。我需要去监听付费音频,后台试听结束,需要pause 一下

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

在付费歌曲播放完成后暂停播放,不跳到下一曲?

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

暂停就行,我看界面里面的进度都是做了个计时器。service应该是拿不到实施进度

from snow.

jrfeng avatar jrfeng commented on July 28, 2024

是的,PlayerService 没有提供监听实时播放进度的 API。

from snow.

cowoboy007 avatar cowoboy007 commented on July 28, 2024

恩。我做个轮询,隔1s查询一次进度吧

from snow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.