- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在我的 Mp3 播放器中制作快进按钮。我已经为此编写了代码,但是有问题如何实现计时器向前跳 5%?我的意思是,当我按下按钮时,计时器应该比总长歌曲向前跳 5%。这是我的 fastForward 方法。
public void FastForward(){
try {
//songTotalLength = fis.available();
fis.skip((long) ((songTotalLength * 0.05)));
} catch (IOException e) {
e.printStackTrace();
}
}
这是按钮方法:
private void jButton3ActionPerformed(ActionEvent e) {
mp3.FastForward();
if(mp3.player.isComplete()){
bar = 100;
}
jProgressBar1.setValue((int)bar);
bar+=5;
}
这个是用于计时器的:
private void setTime(float t) {
int mili = (int) (t / 1000);
int sec = (mili / 1000) % 60;
int min = (mili / 1000) / 60;
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
end.set(Calendar.MINUTE, 0 + min);
end.set(Calendar.SECOND, 0 + sec);
timer = new javax.swing.Timer(1000, new TimerListener());
percent = (float)100/(min*60+sec);
}
最佳答案
您已经在两个变量 fis
和 bar
中冗余地跟踪进度。为了良好的设计,请使用其中一个变量来确定耗时,而不是使用另一个变量来达到相同的目的。
but have problem how to implement timer to jump 5% forward?
您似乎误解了计时器的用途。根据Timer
class documentation ,它:
Fires one or more ActionEvents at specified intervals.
所以计时器并不是为了记录已经过去了多少时间。它只会根据您的配置每秒(每 1000 毫秒)调用 TimerListener
的 actionPerformed(ActionEvent)
方法。
要获得更完整的答案,请发布您的 TimerListener
类的代码。
注释
您的 setTime(float)
方法似乎需要重复调用,因此该方法不应初始化 timer
变量。而是初始化计时器一次,然后让它自行完成其工作。
我假设您希望提供的 float
参数 t
来表示 microseconds .
float
数据类型只有 7 位精度。这可能没问题,因为您只对分钟和秒感兴趣,否则 float 最多只能持续大约四个月的秒,然后就会失去准确性。
您似乎希望按钮点击处理程序执行此操作(更快地增加 bar
):
private void jButton3ActionPerformed(ActionEvent e) {
mp3.FastForward();
bar+=5; // increment bar before checking complete, and before setting progress
if(mp3.player.isComplete()){
bar = 100;
}
jProgressBar1.setValue((int)bar);
}
关于java - java 中带有计时器的 M3 播放器 [快进],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27931537/
我正在使用 just_audio而且效果很好。 但似乎找不到快进或倒带的方法。 更新:原来 just_audio 是 audio_service 的一部分包,使用 audio_service 为我解决
我让它快进了,但我想在快进时听到音乐。我怎样才能做到这一点?这是我的代码: if node.name == "left" { var time = musicPlayer.cu
可以假设快进意味着所有提交都在目标分支上重播并且 HEAD 设置为该分支上的最后一次提交吗? 最佳答案 当您尝试将一个提交与一个可以通过跟踪第一个提交的历史记录到达的提交 merge 时,Git 会通
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 8年前关闭。 Improve this questi
我有一个音频播放器,可以播放从 Core Date 检索到的音频。播放和暂停工作正常。我正在尝试实现“向前跳转 30 秒”按钮,并寻求有关我将如何实现的任何指示。 “播放/暂停”按钮的代码 @IBAc
Git merge 允许我们执行快进和非快进分支 merge 。什么时候使用快进 merge 以及什么时候不使用快进 merge 有什么想法吗? 最佳答案 --no-ff 选项在您想要清楚地了解您的功
我有这种情况:在一些 testBranch 上工作了一段时间,我想与 master 同步所以我做了git checkout testBranch 和git merge master/testBranc
所以我正在做一个项目,我有很长的 for 循环,当接近循环结束时我通常会遇到问题,但是通过进入循环数百万次手动到达那里几乎是不可能的。我知道我可以只更改计数器变量,但在这种情况下它不起作用,因为每次迭
我正在我的 Mp3 播放器中制作快进按钮。我已经为此编写了代码,但是有问题如何实现计时器向前跳 5%?我的意思是,当我按下按钮时,计时器应该比总长歌曲向前跳 5%。这是我的 fastForward 方
MediaPlayer 的 pause() 方法使 Media 稍微“寻找”一下。确实很烦人,但是没找到问题出在哪里。 private void playPauseClicked()
我有一个包含两个分支 master 和 entidades 的 GIT 存储库。我需要将 entidades 分支中的一些内容 merge 到 master 分支。看一下图像,标记为 EntityBu
假设有一个功能分支'my-feature'。在我开发该功能时,有人将它从“我的功能” merge 到“主控”中。因为这是一个快进 merge ,所以没有提交。我所做的一些更改还没有准备好用于 mast
换句话说,快进 merge 是否能保证生成与要 merge 的源分支的 HEAD 相同的 GIT SHA? 我在终端中测试了此行为,它适用于我的测试场景: $ git rev-parse some-b
换句话说,快进 merge 是否能保证生成与要 merge 的源分支的 HEAD 相同的 GIT SHA? 我在终端中测试了此行为,它适用于我的测试场景: $ git rev-parse some-b
这个关于 git 的陈述是真的吗,merge(其中快进是可能的)基本上与使 git reset --hard 到 HEAD 相同要 merge 到的分支? (当merge不是fast-forward时
最近,我创建了newbranch,并创建了一个到Master分支的 merge 请求。在 TeamLead 接受 merge 请求到 Master 分支之前,另一个团队成员向同一个分支(新分支)提交了
我是一名优秀的程序员,十分优秀!