jellyfin / Swiftfin

Native Jellyfin Client for iOS and tvOS
Mozilla Public License 2.0
2.55k stars 279 forks source link

Subtitles missing and duplicating in subtitle selection #1207

Closed felix920506 closed 1 month ago

felix920506 commented 2 months ago

Describe the bug

As shown in the screenshots below, the same video in the web client correctly shows 2 different external subtitle tracks, one zh-hans and one zh-hant. However it shows 2 zh-hans subtitle tracks in Swiftfin. When I enable one of them, both show as enabled. IMG_1613 IMG_1612

I don't really have concrete steps to reproduce so the steps below may not reproduce it properly

  1. Prepare media with multiple external .ass subtitles
  2. Play said media in Swiftfin
  3. Open subtitle selection
  4. See error

Application version

1.1(78)

Where did you install the app from?

App Store

Device information

iPhone 13 Mini

OS version

iOS 17.5.1

Jellyfin server version

10.9.9

cebrusfs commented 1 month ago

+1 here

It seems it happens to any video that have two different subtitle stream. The selection menu will be filled with the duplicate first subtitle. Let says we have X and Y subtile and the menu will shows X and X.

The web client works well without problem. This indicate the app might have something wrong while fetching subtitle streams.

My environment:

Application version

1.1(78)

Where did you install the app from?

App Store

Device information

iPhone iPad

OS version

iOS 18.0

Jellyfin server version

10.9.10

cebrusfs commented 1 month ago

Just curious only this bug, so I jump into this and now I am in day0 to iOS app dev. I spent sometime to setup debugger on my environment.

https://github.com/jellyfin/Swiftfin/blob/a199d69a314aab1bf455528733f7af019ce7a647/Swiftfin/Views/VideoPlayer/Overlays/Components/ActionButtons/AudioActionButton.swift#L28-L39 It seems we use index in ForEach the information here. However, subtitleStreams contain the correct metadata like display title but somehow those index are all mapped to 2 and result in weird behavior.

https://github.com/jellyfin/Swiftfin/blob/a199d69a314aab1bf455528733f7af019ce7a647/Shared/ViewModels/VideoPlayerViewModel.swift#L108-L109 Here is the places creating the wrong indexes. In my debugger, the members of subtitleStreams have index 0 and 1, but the members of subtitleStreams.adjustExternalSubtitleIndexes() have index 2 and 2.

It seems internally copy and index calculation is wrong. Does anyone know what this logic is doing and why we need this? (there is a TODO comment for "explain why adjustment is necessary"....)

cebrusfs commented 1 month ago

In adjustExternalSubtitleIndexes, https://github.com/jellyfin/Swiftfin/blob/a199d69a314aab1bf455528733f7af019ce7a647/Shared/Extensions/JellyfinAPI/MediaStream.swift#L226-L232

Seems 1 + embeddedSubtitleCount + audioStreamCount is a bit strange that because we don't consider multiple subtitles. Its index should increase somehow. maybe currentIndex + 1 + embeddedSubtitleCount + audioStreamCount?