laravelflutterembedrestflutter-video-player

How to get src value in Flutter?


I am pulling data from REST API using Laravel Passport, the data has an embed code, I need to play the video, for which I have to use ext_video_player, how can I get the src value from embed code like this:

<iframe width="560" height="315" src="https://www.youtube.com/embed/fUv9gO8t8b4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

I need to get the value of src.


Solution

  • I dont know if it is string or not but if it is string you can get src like this:

      const str = '<iframe width="560" height="315" src="https://www.youtube.com/embed/fUv9gO8t8b4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
      const start = 'src="';
      const end = '" frameborder';
    
      final startIndex = str.indexOf(start);
      final endIndex = str.indexOf(end, startIndex + start.length);
    
      print(str.substring(startIndex + start.length, endIndex)); // https://www.youtube.com/embed/fUv9gO8t8b4