admin管理员组文章数量:1406924
Im trying to create a blob url to use string as file for JwPlayer subtitles.
subtitles are loaded like this:
const playlistItem = {
...
tracks: [
{
file: '.vtt',
label: 'en'
}
]
}
So because jwplayer dont accept my source (subtitles.ass) i converted .ass to .vtt resulting as string.
Like this:
var vttRaw = `WEBVTT
00:00:25.520 --> 00:00:29.250
Naquele dia,
a humanidade foi lembrada...
00:00:35.110 --> 00:00:38.180
do terror de estar à mercê deles`;
As jwplayer needs a url, i converted this string to blob url:
//Generate blob
var blob = new Blob([vttRaw], {
type: "text/vtt; charset=utf-8"
});
//Generate url
var vtt_url = URL.createObjectURL(blob) + "#.vtt";
In web browser that works, but in react-native-android results in a error.
Possible Unhandled Promise Rejection (id: 0):
Error: Cannot create URL for blob!
blob error
I think the problem is to generate a blob url, anyone know what can i do?
Im trying to create a blob url to use string as file for JwPlayer subtitles.
subtitles are loaded like this:
const playlistItem = {
...
tracks: [
{
file: 'https://myfakesite/subtitles.vtt',
label: 'en'
}
]
}
So because jwplayer dont accept my source (subtitles.ass) i converted .ass to .vtt resulting as string.
Like this:
var vttRaw = `WEBVTT
00:00:25.520 --> 00:00:29.250
Naquele dia,
a humanidade foi lembrada...
00:00:35.110 --> 00:00:38.180
do terror de estar à mercê deles`;
As jwplayer needs a url, i converted this string to blob url:
//Generate blob
var blob = new Blob([vttRaw], {
type: "text/vtt; charset=utf-8"
});
//Generate url
var vtt_url = URL.createObjectURL(blob) + "#.vtt";
In web browser that works, but in react-native-android results in a error.
Possible Unhandled Promise Rejection (id: 0):
Error: Cannot create URL for blob!
blob error
I think the problem is to generate a blob url, anyone know what can i do?
Share Improve this question asked Dec 9, 2020 at 12:26 user11807888user118078881 Answer
Reset to default 6I had this issue in React Native for Android. The following worked in iOS but not Android
URL.createObjectURL(blob)
Try passing base64 data rather than the url, like in this post.
Maybe something like this:
//Generate blob
var blob = new Blob([vttRaw], {
type: "text/vtt; charset=utf-8"
});
const fileReaderInstance = new FileReader();
fileReaderInstance.readAsDataURL(blob);
fileReaderInstance.onload = () => {
base64 = fileReaderInstance.result;
vtt_data = base64;
}
本文标签: javascriptReact native (Android)Create URLcreateObjectURL(blob)Stack Overflow
版权声明:本文标题:javascript - React native (Android) - Create URL.createObjectURL(blob) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744374256a2603178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论