gpt4 book ai didi

cordova typescript 媒体插件 MediaPlayer

转载 作者:行者123 更新时间:2023-12-02 16:53:17 27 4
gpt4 key购买 nike

在 Visual Studio Community 2017 中,我从“Ionic 2 - Sidemenu”模板开始。 (Ionic2、Angular2、TypeScript)我想使用 Media cordova 插件,并播放(音频)mp3 文件。案例:应用程序打开 > 显示音频控件 > Actor 点击播放按钮 > 音频文件播放。

在 VS 中,我使用 config.xml > 插件 UI 来安装插件。然后在我的 app.component.ts 文件中,我将其放在顶部。

import { MediaPlugin } from 'ionic-native';

这在同一个文件中

initializeApp() {
this.platform.ready().then(() => {
console.log(MediaPlugin);
});
}

这会在控制台中显示出来。 enter image description here

问题#1:我必须做什么

var myPlayer = new Media(src, success, fail) 

ts 文件中的某个位置?我想我必须使用不同的代码,因为我使用的是 TypeScript。

问题#2:我应该在 html 中添加什么内容才能在 UI 中显示媒体播放器?我现在在 html 中有这个

<audio controls></audio>

但也许我需要其他东西,因为我正在使用 ionic 。

目前,我尝试让播放器使用此按钮播放 mp3 文件作为按钮单击处理程序:

setSrc() {
var myPlayer = document.getElementsByTagName('audio')[0];
// the intellisense verifies that this path is correct
myPlayer.src = '../../audio/Capitolo_7s.mp3';
}

我在媒体播放器的 UI 中收到错误:

This type of audio file isn't supported

谢谢。

最佳答案

Ionic 有一个 cordova native 插件的包装器

在此链接中查看他们的文档和用法 Ionic Native - Media

关于cordova typescript 媒体插件 MediaPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46107857/

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