我正在尝试使代码2 正常工作
该代码中的这一行需要进行调整,但是我不知道如何解决。
public void AlarmForQuote() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 21);
calendar.set(Calendar.MINUTE, 28);
Calendar cur = Calendar.getInstance();
if (cur.after(calendar)) {
calendar.add(Calendar.DATE, 1);
}
mTodaysQuoteIntent = new Intent(this,
TodaysQuoteAlarmReceiver.class);
int ALARM_ID = 10000;
mTodaysQuotePendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), ALARM_ID, mTodaysQuoteIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mNewTodaysQuote = (AlarmManager) getSystemService(ALARM_SERVICE);
mNewTodaysQuote.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, mTodaysQuotePendingIntent);
}
点击第二个视频后,暂停之前的视频。
这有效:代码1
https://jsfiddle.net/d72Lp43v/418/
const otherVideos = (video) => video !== player.getVideoUrl() !== temp;
该代码没有,怎么来?
代码2
https://jsfiddle.net/d72Lp43v/421/
function onPlayerStateChange(event) {
if (event.data === YT.PlayerState.PLAYING) {
const temp = event.target.getVideoUrl();
const otherVideos = (player) => player.getVideoUrl() !== temp;
const pauseVideo = (player) => player.pauseVideo();
players.filter(otherVideos).forEach(pauseVideo);
}
const player = event.target;
const playerVars = player.b.b.playerVars;
if (playerVars.loop && event.data === YT.PlayerState.ENDED) {
player.seekTo(playerVars.start);
}
}
答案 0 :(得分:2)
只需将该行更改为:
const otherVideos = video => video.getVideoUrl() != player.getVideoUrl()
这将做您想要的。通过比较filter
字符串,可以确保urls
不包括当前视频。
您还可以通过这种方式不需要temp
变量。
答案 1 :(得分:0)
players.filter(otherVideos)
我认为过滤器总是返回完整列表。
每个播放器都不是URL,因此video !== player.getVideoUrl()
是true
。并且true
不是URL。 true !== temp
也是如此。
我不知道您要改善代码1。 但是我认为您要写的是以下内容:
function onPlayerStateChange(event) {
const player = event.target;
if (event.data === YT.PlayerState.PLAYING) {
const temp = event.target.getVideoUrl();
// only change this line:
const otherVideos = (video) => video.getVideoUrl() !== player.getVideoUrl() && video.getVideoUrl() !== temp;
const pauseVideo = (video) => video.pauseVideo();
players.filter(otherVideos).forEach(pauseVideo);
}
const playerVars = player.b.b.playerVars;
if (playerVars.loop && event.data === YT.PlayerState.ENDED) {
player.seekTo(playerVars.start);
}
}