Angular 用于爱奥尼亚4的Webtorrent客户端/播放器
我想将Webtorrent应用到爱奥尼亚4应用程序中。我已经成功地玩了。m3u8流畅无瑕。我现在需要的是我不太熟悉的webtorrent部分 我正在为.m3u8流使用Angular 用于爱奥尼亚4的Webtorrent客户端/播放器,angular,ionic-framework,media-player,ionic4,webtorrent,Angular,Ionic Framework,Media Player,Ionic4,Webtorrent,我想将Webtorrent应用到爱奥尼亚4应用程序中。我已经成功地玩了。m3u8流畅无瑕。我现在需要的是我不太熟悉的webtorrent部分 我正在为.m3u8流使用标记,它在Ionic 4中似乎运行良好。我希望能够下载torrent视频文件,并使用标签或视频播放器组件在Ionic上流/播放视频 求你了,我需要帮助。我一直在尝试所有我知道的和我能在网上找到的东西,但到目前为止没有任何帮助。任何帮助都将不胜感激 提前谢谢。 这就是我在尝试实现时遇到的错误。任何人都知道可能是什么问题 这是我
标记,它在Ionic 4中似乎运行良好。我希望能够下载torrent视频文件,并使用
标签或视频播放器组件在Ionic上流/播放视频
求你了,我需要帮助。我一直在尝试所有我知道的和我能在网上找到的东西,但到目前为止没有任何帮助。任何帮助都将不胜感激
提前谢谢。
这就是我在尝试实现时遇到的错误。任何人都知道可能是什么问题 这是我的代码的快照 告诉我你们的想法
提前谢谢。好的,在尝试了几天不同的方法后,我找到了解决方案。顺便说一句,真的很简单 这里有一个
这是我使用的代码
import { WebTorrent } from 'webtorrent';
declare var WebTorrent: WebTorrent;
....
playVideo() {
const client = WebTorrent();
const magnetURL = 'https://webtorrent.io/torrents/sintel.torrent';
client.add(magnetURL, function (torrent) {
// document.getElementById('hash').textContent = 'Client downloading: ' + torrent.infoHash;
torrent.files.forEach(function (file) {
torrent.on('download', function (bytes) {
document.getElementById('download').textContent = 'just downloaded: ' + bytesToSize(bytes);
document.getElementById('tdownload').textContent = 'total downloaded: ' + bytesToSize(torrent.downloaded);
document.getElementById('sdownload').textContent = 'download speed: ' + bytesToSize(torrent.downloadSpeed);
document.getElementById('pdownload').textContent = toPercentage(torrent.progress);
});
torrent.files.find(function (file) {
return file.name.endsWith('.mp4') || file.name.endsWith('.avi') || file.name.endsWith('.mkv') || file.name.endsWith('.mpeg');
});
file.renderTo('#video', function (err, element) {
presentToast(magnetURL);
});
});
});
function presentToast(text: string) {
this.presentToast(text);
}
function bytesToSize(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) { return '0 Bytes'; }
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
function toPercentage(dec) {
dec = dec.toString();
const a = dec.split('.');
dec = a[1];
dec = dec.substr(0, 4);
return dec = (dec / 100) + '%';
}
}
不过我有两个问题。我只能在sintel.mp4达到99.89%时播放它,但我希望能够在下载时播放它。
我的第二个问题是,我只能下载并播放Sintel.torrent。我尝试使用其他磁铁链接,但它没有任何作用。我猜这与磁铁url的生成方式有关 对于第二个问题,请使用磁铁进行测试,因为webtorrent使用带有webtorrent跟踪器的torrents。
import { WebTorrent } from 'webtorrent';
declare var WebTorrent: WebTorrent;
....
playVideo() {
const client = WebTorrent();
const magnetURL = 'https://webtorrent.io/torrents/sintel.torrent';
client.add(magnetURL, function (torrent) {
// document.getElementById('hash').textContent = 'Client downloading: ' + torrent.infoHash;
torrent.files.forEach(function (file) {
torrent.on('download', function (bytes) {
document.getElementById('download').textContent = 'just downloaded: ' + bytesToSize(bytes);
document.getElementById('tdownload').textContent = 'total downloaded: ' + bytesToSize(torrent.downloaded);
document.getElementById('sdownload').textContent = 'download speed: ' + bytesToSize(torrent.downloadSpeed);
document.getElementById('pdownload').textContent = toPercentage(torrent.progress);
});
torrent.files.find(function (file) {
return file.name.endsWith('.mp4') || file.name.endsWith('.avi') || file.name.endsWith('.mkv') || file.name.endsWith('.mpeg');
});
file.renderTo('#video', function (err, element) {
presentToast(magnetURL);
});
});
});
function presentToast(text: string) {
this.presentToast(text);
}
function bytesToSize(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) { return '0 Bytes'; }
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
function toPercentage(dec) {
dec = dec.toString();
const a = dec.split('.');
dec = a[1];
dec = dec.substr(0, 4);
return dec = (dec / 100) + '%';
}
}