Skip to content

Commit df29b76

Browse files
committed
fix: update media item handling for seamless looping
1 parent 2686d33 commit df29b76

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/assets/playlist_data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
]
116116
},
117117
{
118-
"id": "right",
118+
"id": "right_bottom",
119119
"position": {
120120
"x": 640,
121121
"y": 360,

src/hooks/useSectionMediaItems.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const useSectionMediaItems = (sectionItems: Item[]) => {
66
const totalDurationRef = useRef<number>(0)
77

88
useEffect(() => {
9-
const items = sectionItems.map(item => ({
9+
let items = sectionItems.map(item => ({
1010
id: item.id,
1111
src: item.content_path,
1212
type: item.content_type,
@@ -15,6 +15,13 @@ export const useSectionMediaItems = (sectionItems: Item[]) => {
1515
preload: false,
1616
}))
1717

18+
// If the section contains only one item, duplicate it to enable seamless looping of the media
19+
if (items.length === 1) {
20+
const duplicate = { ...items[0], id: `${items[0].id}-copy` }
21+
22+
items = [...items, duplicate]
23+
}
24+
1825
totalDurationRef.current = items.reduce((sum, item) => sum + item.duration, 0)
1926

2027
setMediaItems(items)

0 commit comments

Comments
 (0)