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

标签 android telerik hybrid-mobile-app nativescript

我一直在阅读文档 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/

相关文章:

android - 凹轮廓上的 Lollipop 高度

flutter - 用Flutter构建网格布局

android - App 和 Play 商店中的定制应用程序

java - 如何为 ListView 中的项目设置 onClickListener(listview 的项目是通过从 firebase 检索数据动态生成的)

android - 使用 NotificationCompat .addAction 按钮停止前台服务

javascript - Xamarin 和 Telerik 平台有什么区别

telerik - 添加 Telerik StyleSheetRegistrar 创建的链接的媒体类型

javascript - 如何做 ajax 请求并从 Android Webview 获得响应?

android - 在 Flutter 中显示 100 张或更多图像的最快方法

c# - ASP.NET 随机字符串出现在 URL 中