我一直在阅读文档 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 并进行调用。
媒体播放器的文档:
- 安卓:http://developer.android.com/guide/topics/media/mediaplayer.html
- iOS:https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVPlayer_Class/index.html和 https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/
同样好的阅读是 NativeScripts documentation on how to call the native APIs from NativeScript .
关于android - 有没有办法在 NativeScript 中播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30997824/