我有一个用Elm编写的应用程序,可以播放在Electron中显示的潘多拉音乐。多数情况下,一首歌结束后,它会照常移至下一首歌,但偶尔如果窗口没有聚焦并且在另一首歌的后面(通常当我仅使用一个显示器时),进度条将保持移动但只有在聚焦窗口之前,音频才会播放。有谁知道这可能是什么原因?
onEnded
(case (gm.currentStation) of
Just station ->
station.id
Nothing ->
""
)
, id "songAudio"
, src
(case (List.head gm.songQueue) of
Just song ->
song.audioURL
Nothing ->
""
)
, autoplay True
]
[]
onEnded : String -> Attribute Msg
onEnded stationId =
Html.Events.on "ended"
(Decode.succeed (SongEnded stationId))
( { gm
| songQueue = (List.drop 1 gm.songQueue)
, previousSongs =
(case List.head gm.songQueue of
Just song ->
song
Nothing ->
{ songTitle = ""
, trackLength = 0
, rating = 0
, audioURL = ""
, artistName = ""
, albumTitle = ""
, albumArt = ""
, trackToken = ""
}
)
:: gm.previousSongs
, currentTime = 0
, isPlaying = True
}
, cmds
[ if List.length gm.songQueue == 2 then
Http.send LoadedNextSongs
(SongApi.getNext stationId gm.authToken False)
else
Cmd.none
]
)
在大多数情况下,它会继续正常播放歌曲,但有时直到我重新调整窗口的焦点时才开始播放歌曲。 (尽管进度条一直在计数,所以导致其播放的代码应该可以正常工作。)