我正在使用离子显示视频在一个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')
);
}
}发布于 2018-09-03 17:38:33
我试过了,这对我有帮助。
从“@离子型-自然/失眠症”进口{失眠};
构造函数(公共navCtrl: NavController,公共失眠:失眠){ this.insomnia.keepAwake() .then( () => console.log('success'),() => console.log('error keepAlive') );}
https://stackoverflow.com/questions/52137838
复制相似问题