Git Product home page Git Product logo

Comments (22)

qq326646683 avatar qq326646683 commented on August 15, 2024

你好,你可以监听播放完毕,然后去播放下一集的url

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

腾讯的X5浏览器 播放视频好像内置网络加速,不知道作者这个插件是不同样支持

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

不太清楚浏览器端,目前没有打算兼容web端

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

如何监听当前播放结束?

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

我通过判断时长是否等于播放位置,来确定是不是播放完。controller.value.position.inSeconds ==
controller.value.duration.inSeconds
有没有其他方法

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

我这两天抽空把播放结束的事件传出来,可以监听bool isPlayEnd = controller.value.playEnd 。完事告诉你

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

我这两天抽空把播放结束的事件传出来,可以监听bool isPlayEnd = controller.value.playEnd 。完事告诉你

好的,谢谢,我通过比较视频长度 和播放进度是否相等判断当前视频是否播放完成,貌似不行,还容易进死循环。

cachePath是不是必须设置才有效?

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

已经解决!
配合path_provider 设置缓存路径 播放网络视频体验快很多

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

厉害了👍,记得对你设置缓存目录清理哦,它会缓存到本地。不然app占的空间越来越大

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

厉害了+1,记得对你设置缓存目录清理哦,它会缓存到本地。不然app占的空间越来越大

有两个方案:
一,在full_video_page dispose里清理,用户每次跳出页面自动清理
二,App设置页面单独设置个清理按钮

我比较倾向第一种。

另外建议,作者example里把cachePath设置好,这样体验快很多。也给想集成该插件的开发者良好的体验,增加集成欲望。

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

谢谢提出宝贵意见,后续版本将改进

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

缓存目录在cache/txvodcache下吧?
我退出播放界面后删除该文件夹,后面不管是重装 还是卸载重装,都不会重建这个目录怎么回事

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

缓存目录你可以自己设置,当然该文件夹要存在哦

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

`_initController() {
_getAppCachePath();
print('缓存目录' + appCachePath);
if (widget.controller != null) {
controller = widget.controller;
return;
}
switch (widget.playType) {
case PlayType.network:
controller = TencentPlayerController.network(widget.dataSource,
playerConfig: PlayerConfig(cachePath: appCachePath));
break;
case PlayType.asset:
controller = TencentPlayerController.asset(widget.dataSource);
break;
case PlayType.file:
controller = TencentPlayerController.file(widget.dataSource);
break;
case PlayType.fileId:
controller = TencentPlayerController.network(null,
playerConfig: PlayerConfig(
auth: {"appId": 1251203810, "fileId": widget.dataSource}));
break;
}
controller.initialize();
controller.addListener(listener);
setState(() {});
}

_getAppCachePath() async {
Directory appCacheDir = await getTemporaryDirectory();

setState(() {
  appCachePath = appCacheDir.path;
});

}`

print('缓存目录' + appCachePath); 获取不到appCachePath的值 为空。这怎么解决

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

你的写法看上去有问题,_getAppCachePath 和print()是同步,但_getAppCachePath是异步,你应该String cachePath = (await _getAppCachePath()).path;

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

initController() async {
await getTemporaryDirectory().then((result) {
setState(() {
appCachePath = result.path;
});
}).then((
) {
print('缓存目录:'+appCachePath);
if (widget.controller != null) {
controller = widget.controller;
return;
}
switch (widget.playType) {
case PlayType.network:
controller = TencentPlayerController.network(widget.dataSource,
playerConfig: PlayerConfig(cachePath: appCachePath));
break;
case PlayType.asset:
controller = TencentPlayerController.asset(widget.dataSource);
break;
case PlayType.file:
controller = TencentPlayerController.file(widget.dataSource);
break;
case PlayType.fileId:
controller = TencentPlayerController.network(null,
playerConfig: PlayerConfig(
auth: {"appId": 1251203810, "fileId": widget.dataSource}));
break;
}
controller.initialize();
controller.addListener(listener);
setState(() {});
});
}

这样写可以顺利创建缓存目录,但因为是_initController是异步,这样controller.initialize(); ontroller.addListener(listener);就有问题了。

/// 视频
controller.value.initialized
? AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: TencentPlayer(controller),
)
: Image.asset('images/tencentplayer/place_nodata.png'),

这里controller在build的时候就为空了

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

你可以,controller != null ? TencentView : SizedBox()或者进app就把getTemporaryDirectory()的返回值存下来,自己想想办法,这应该难不到你

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

感谢点拨。在合适的地方,获取到缓存路径 配合preferences持久化,搞定

from flutter_tencentplayer.

qq326646683 avatar qq326646683 commented on August 15, 2024

关于播放完成的监听,我看了一下代码,之前就接入了,可以通过postion==duration来判断:
_FullVideoPageState() {
listener = () {
if (!mounted) {
return;
}
if (controller.value.position == controller.value.duration) {
print('playEnd');
}
setState(() {});
};
}

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

关于播放完成的监听,我看了一下代码,之前就接入了,可以通过postion==duration来判断:
_FullVideoPageState() {
listener = () {
if (!mounted) {
return;
}
if (controller.value.position == controller.value.duration) {
print('playEnd');
}
setState(() {});
};
}

这个方法我试过,但有个bug 因为视频刚加载中获取不到时长,也没播放进度,进死循环了

from flutter_tencentplayer.

shipinbaoku avatar shipinbaoku commented on August 15, 2024

_FullVideoPageState() {
listener = () {
if (!mounted) {
return;
}
if (controller.value.position.inSeconds >= 10) {
if (controller.value.position.inSeconds ==
controller.value.duration.inSeconds) {
var hasData = widget.urlsList.indexWhere((item) {
return item.url == widget.dataSource;
});
if (hasData != -1) {
print('监听到了');
print(hasData);
setState(() {
widget.dataSource =
widget.urlsList[widget.currentClearIndex + 1].url;
});
}
}
}
//setState(() {});
};
}

我是将播放地址, 播放地址列表,播放地址在列表中的索引位置都传过来,然后通过索引+1去获取下一集的播放地址。

通过controller.value.position.inSeconds ==
controller.value.duration.inSeconds去判断是否播放完成 就死循环了。

print('监听到了'); 一直打印

from flutter_tencentplayer.

lylelqc avatar lylelqc commented on August 15, 2024

_FullVideoPageState() {
listener = () {
if (!mounted) {
return;
}
if (controller.value.position.inSeconds >= 10) {
if (controller.value.position.inSeconds ==
controller.value.duration.inSeconds) {
var hasData = widget.urlsList.indexWhere((item) {
return item.url == widget.dataSource;
});
if (hasData != -1) {
print('监听到了');
print(hasData);
setState(() {
widget.dataSource =
widget.urlsList[widget.currentClearIndex + 1].url;
});
}
}
}
//setState(() {});
};
}

我是将播放地址, 播放地址列表,播放地址在列表中的索引位置都传过来,然后通过索引+1去获取下一集的播放地址。

通过controller.value.position.inSeconds ==
controller.value.duration.inSeconds去判断是否播放完成 就死循环了。

print('监听到了'); 一直打印

老哥,你解决了吗,我用inMilliseconds就只有一次了

from flutter_tencentplayer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.