regex - Flutter Dart:如何从视频 URL 中提取 youtube 视频 ID?
问题描述
如何使用 dart 正则表达式从视频 URL 中提取 YouTube 视频 ID?
示例网址
https://www.youtube.com/watch?v=SEkUienM2oY&t=1265s
或者
https://m.youtube.com/watch?v=SEkUienM2oY&t=1265s
返回
SEkUienM2oY&t=1265s
它为我工作
String getVideoID(String url) {
url = url.replaceAll("https://www.youtube.com/watch?v=", "");
url = url.replaceAll("https://m.youtube.com/watch?v=", "");
return url;
}
但是如何用正则表达式做到这一点?
解决方案
没有正则表达式,我希望这能完美工作 将此依赖项添加到您的 pubspec.yaml 文件中
youtube_player_flutter: ^6.1.0+4
try {
videoIdd = YoutubePlayer.convertUrlToId("your url here");
print('this is '+videoId);
} on Exception catch (exception) {
// only executed if error is of type Exception
print('exception');
} catch (error) {
// executed for errors of all types other than Exception
print('catch error');
// videoIdd="error";
}
推荐阅读
- wpf - 当 app.config 中的其他模块设置为 Startup 时自动加载 OnDemand prism 模块
- javascript - 我是否以字符串形式分配对函数或函数的引用?
- ios - 获取包含不超过两个字母的日历工作日符号
- matlab - 预期区域外的飞机
- ios - 在后台模式和终止模式下获取位置更新 IOS
- javascript - 使 div 不透明度像线性渐变一样变化
- imagemagick - ImageMagick 在不使用大量磁盘的情况下创建大的空白图像
- google-apps-script - 如何为使用 AppMaker 创建(从 HTML)和通过电子邮件发送的 PDF 设置页面大小?
- java - 为什么除法运算符不能正常工作?
- ruby-on-rails - 如何在狂欢中获得购物车订单项?