【问题标题】:Is there a way to play a video in NativeScript?有没有办法在 NativeScript 中播放视频?
【发布时间】:2015-09-08 23:01:50
【问题描述】:

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

【问题讨论】:

    标签: android telerik hybrid-mobile-app nativescript


    【解决方案1】:

    新答案(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,您可以调用本机 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 也不错。

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 2020-08-07
      相关资源
      最近更新 更多