0

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.

Thientvse
  • 1,753
  • 1
  • 14
  • 23
shishir kumar
  • 23
  • 1
  • 8

2 Answers2

0

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
Babak Asadzadeh
  • 1,207
  • 1
  • 11
  • 21
0

Using this package universal_html


import 'package:universal_html/html.dart' as html;
import 'package:universal_html/parsing.dart' as parser;

final htmlDocument = parser.parseHtmlDocument(
            '<iframe width="560" height="315" src="https://www.youtube.com/embed/8zM-CrtJmG" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>');

log('${(htmlDocument.getElementsByTagName('iframe').first as html.IFrameElement).src}');

Mayor
  • 303
  • 2
  • 7