wang-bin / fvp

Flutter video player plugin for all desktop+mobile platforms. download prebuilt examples from github actions. https://pub.dev/packages/fvp
BSD 3-Clause "New" or "Revised" License
197 stars 31 forks source link

Can't alternate between external/internal subtitles #166

Open azukaar opened 1 month ago

azukaar commented 1 month ago

I am currently setting subtitles this way:

        var subList = subtitleTracks.asMap().entries.map((entry) {
          int index = entry.key;
          var track = entry.value;

          var title = track.metadata['title'] ??
              track.metadata['language'] ??
              'Unknown';

          return ListTile(
            title: Text(title),
            onTap: () {
              player.activeSubtitleTracks = [index];
              closeDialog();
            },
          );
        }).toList();

        for (var exSub in widget.item.subtitles) {
          subList.add(ListTile(
            title: Text(exSub.language),
            onTap: () {
              player.setMedia(
                  "${widget.item.originURL}${exSub.link}", MediaType.subtitle);
              closeDialog();
            },
          ));
        }

This is building a list of subtitles, that are clickable. I can individually either set an internal OR external subtitles on a video. BUT if I set an external subtitle, I have to call player.setMedia, and after that, subsequent attempts at setting internal subtitle will fail. I attempted to fix the issue by recalling setMedia() for internal subtitle like this (with the video stream URL):

  onTap: () {
              print('Selected subtitle track: $index');
              player.setMedia("${widget.item.originURL}${widget.item.stream}",
                  MediaType.subtitle);
              player.activeSubtitleTracks = [index];
              closeDialog();
            },

It works, if I select an external and then an internal one, it will select it. But when i do this, if I select an internal subtitle (which is going to call SetMedia with the video) THEN an external subtitle, the player just freezes, so I am assuming I'm not supposed to do that

Thanks for your help

wang-bin commented 1 month ago

can you provide a complete minimal code so I can test?