我正在使用离子技术在iframe
中显示视频。我尝试使用离子型的Insomnia
和Blacklight
,但无济于事。当我在Android设备上播放视频时,在视频持续播放的30秒后,屏幕变暗。如何防止屏幕变暗?例如,当我使用YouTube应用程序时,我的屏幕始终保持不动。
home.html
<p> This is the Iframe in Html File </p>
<p>
<iframe width="100%" height="370" (click)="keepAlive()" [src]="video.video | youtube" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</p>
home.ts
import { Component } from '@angular/core';
import {NavController } from 'ionic-angular';
import { VideoPlayer , VideoOptions} from '@ionic-native/video-player';
import { Insomnia } from '@ionic-native/insomnia';
import { Backlight } from '@ionic-native/backlight';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
videos: any[] = [
{
video: 'https://www.youtube.com/embed/e234gfdd?autohide=1&playsinline=1&showinfo=0',
title: 'demo1'
},
{
video: 'https://www.youtube.com/embed/3erghj75?autohide=0&playsinline=1&showinfo=0',
title: 'demo 2'
}
];
videoOpts : VideoOptions ;
constructor(public navCtrl: NavController ,private backlight: Backlight,
public videoPlayer : VideoPlayer,public insomnia: Insomnia) {
}
keepAlive() {
console.log("called");
this.backlight.on().then(() => console.log('backlight on'));
this.insomnia.keepAwake()
.then(
() => console.log('success'),
() => console.log('error keepAlive')
);
}
sleepNow() {
this.insomnia.allowSleepAgain()
.then(
() => console.log('success'),
() => console.log('error sleepNow')
);
}
}
答案 0 :(得分:0)
我尝试了这个,对我有帮助。
从'@ ionic-native / insomnia'导入{失眠};
构造函数(公共navCtrl:NavController,公共失眠:失眠){ this.insomnia.keepAwake() 。然后( ()=> console.log('success'), ()=> console.log('错误keepAlive') ); }