我从 Ionic 4 开始,我尝试创建一个可以在后台播放媒体(流)的应用程序,比如 youtube。我在我的:_home.page.ts
import { Component } from '@angular/core';
import { YoutubeVideoPlayer } from '@ionic-native/youtube-video-player/ngx';
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(
private youtube: YoutubeVideoPlayer,
private backgroundMode: BackgroundMode
) {
}
openMyVideo(id:string) {
this.backgroundMode.on("activate").subscribe(() => {
this.backgroundMode.disableWebViewOptimizations();
});
this.backgroundMode.on("enable").subscribe(() => {
this.youtube.openVideo(id);
});
this.backgroundMode.enable();
}
}
这是我的home.page.html
:
<ion-header>
<ion-toolbar>
<ion-title>
YouTube Player
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-button (click)="openMyVideo('xxxxxxxxxxx')">Open Video</ion-button>
</ion-content>
到目前为止它可以工作,但是当我锁定屏幕(iOS和Andriod)时视频会停止,但我想继续播放。他们是我缺少的东西还是我必须嵌入视频或其他东西?甚至有可能吗..?
在此先感谢您的帮助!