gpt4 book ai didi

android - 有没有办法在 NativeScript 中播放视频?

转载 作者:可可西里 更新时间:2023-10-31 22:03:34 26 4
gpt4 key购买 nike

我一直在阅读文档 https://docs.nativescript.org/modules但我只能找到一个图像小部件。欢迎所有建议。提前致谢!

最佳答案

新答案(2016 年 11 月 10 日编辑)

现在有一个跨平台视频播放器模块可用。只需下载并运行:https://github.com/bradmartin/nativescript-videoplayer

例如

<Page xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:VideoPlayer="videoplayer">
<StackLayout>
<VideoPlayer:Video
loaded="videoplayerLoaded"
finished="videoFinished"
autoplay="true"
height="300"
src="~/videos/small.mp4"
/>
</StackLayout>
</Page>

旧答案

目前,没有内置的跨平台模块(如图所示)来播放视频。有一个 open issue就此主题而言。但是,由于这是 NativeScript,您可以调用 native API(这就是 NativeScript 脱颖而出的原因)。

下面是一个如何调用 iOS AVAudioPlayer 的例子:

var Clicker = function(resource) {
var soundPath = NSBundle.mainBundle().pathForResourceOfType("app/"+resource, "mp3");
var soundUrl = NSURL.fileURLWithPath(soundPath);
var player = AVAudioPlayer.alloc().initWithContentsOfURLError(soundUrl, null);
player.prepareToPlay();

this.click = function() {
player.currentTime = 0.0;
player.play();
};
};
module.exports.Clicker = Clicker;

完整示例,请参阅https://www.nativescript.org/blog/calcunator-the-nativescript-calculator

您要做的是查看每个平台的 API 并进行调用。

媒体播放器的文档:

同样好的阅读是 NativeScripts documentation on how to call the native APIs from NativeScript .

关于android - 有没有办法在 NativeScript 中播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30997824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com