ExoPlayer not closing when i press the backbutton
Closed this issue · 1 comments
hi! i'm trying to close exoplayer when i press the backbutton, however i can't, the player keeps playing the data stream.
Here´s my code, i'm using ionic 5.
home.ts
import
{ Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Platform } from '@ionic/angular';
declare var ExoPlayer;
@component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss']
})
export class HomePage {
data: any;
constructor(
public http: HttpClient,
public platform: Platform
) {
this.getData();
this.platform.backButton.subscribe(() => {
alert("back button pressed");
console.log("backbutton");
ExoPlayer.close();
});
}
getData(){
let url = "https://cors-anywhere.herokuapp.com/https://pastebin.com/raw/5ugfxD2f";
this.http.get(url).subscribe(data =>{
this.data = data;
});
}
play(url, type) {
var streamurl = url;
var type = type;
var params = {
user_agent: "PluginExoPlayer",
url: streamurl,
showBuffering: false,
full_screen: true,
aspectRatio: "FILL_SCREEN",
}
switch (type) {
case "hls":
ExoPlayer.show(params).subscribe(result => {
if (result.eventType == 'KEY_EVENT') {
ExoPlayer.close();
}
});
break;
case "embed":
alert("este canal no tiene enlace directo");
break;
}
}
}`