正在查看: Mint v5.7.3 应用的 TtsPlayerService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Mint v5.7.3 应用的 TtsPlayerService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.htmedia.mint.ttsplayer;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ServiceLifecycleDispatcher;
import androidx.media.MediaBrowserServiceCompat;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator;
import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerNotificationManager;
import com.google.android.exoplayer2.util.Util;
import com.htmedia.mint.pojo.Content;
import com.htmedia.mint.ttsplayer.TtsPlayerService;
import com.htmedia.mint.ui.activity.DeepLinkActivity;
import com.htmedia.mint.utils.m0;
import com.htmedia.mint.utils.n;
import com.htmedia.mint.utils.o0;
import com.htmedia.sso.helpers.ToastHelper;
import com.thoughtbot.expandablerecyclerview.BuildConfig;
import f6.l;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import m7.g;
import m7.h;
import m7.i;
import m7.r;
import x4.ed;
import x4.ks0;
public class TtsPlayerService extends MediaBrowserServiceCompat implements LifecycleOwner, PlayerNotificationManager.NotificationListener, Player.Listener {
public static h A;
public static long B;
ed c;
ks0 d;
WindowManager e;
WindowManager.LayoutParams f;
private Point g;
private DisplayMetrics h;
private boolean i;
private ExoPlayer o;
private i p;
private MediaSessionCompat q;
private MediaSessionConnector r;
private Formatter t;
private final ServiceLifecycleDispatcher a = new ServiceLifecycleDispatcher(this);
int b = 0;
private boolean j = false;
private final StringBuilder s = new StringBuilder();
public boolean u = false;
public boolean v = false;
private boolean w = false;
private boolean x = false;
private boolean y = false;
private boolean z = false;
class a extends TimelineQueueNavigator {
a(MediaSessionCompat mediaSessionCompat) {
super(mediaSessionCompat);
}
@NonNull
public MediaDescriptionCompat getMediaDescription(@NonNull Player player, int i) {
return g.a.getDescription();
}
}
class b implements Player.Listener {
b() {
}
public void onEvents(Player player, Player.Events events) {
super.onEvents(player, events);
}
public void onIsPlayingChanged(boolean z) {
super.onIsPlayingChanged(z);
h hVar = TtsPlayerService.A;
if (hVar != null && (hVar instanceof h)) {
hVar.a(z, g.g());
}
if (!z) {
l.m(TtsPlayerService.this.getApplicationContext(), g.g(), Long.valueOf(TtsPlayerService.this.d.c.getPlayer().getCurrentPosition()));
return;
}
l.m(TtsPlayerService.this.getApplicationContext(), g.g(), 0);
l.m(TtsPlayerService.this.getApplicationContext(), "runningPlayerID", g.g() + BuildConfig.FLAVOR);
}
public void onPlayWhenReadyChanged(boolean z, int i) {
super.onPlayWhenReadyChanged(z, i);
}
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
super.onPlaybackParametersChanged(playbackParameters);
}
public void onPlaybackStateChanged(int i) {
super.onPlaybackStateChanged(i);
if (i == 4) {
n4.b.E(g.d(), false, true);
}
}
public void onPlaybackSuppressionReasonChanged(int i) {
super.onPlaybackSuppressionReasonChanged(i);
}
public void onPlayerError(PlaybackException playbackException) {
super.onPlayerError(playbackException);
}
public void onRepeatModeChanged(int i) {
super.onRepeatModeChanged(i);
}
public void onShuffleModeEnabledChanged(boolean z) {
super.onShuffleModeEnabledChanged(z);
}
}
class c implements View.OnTouchListener {
c() {
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
}
class d implements View.OnClickListener {
d() {
}
@Override
public void onClick(View view) {
TtsPlayerService.this.j = !r3.j;
TtsPlayerService ttsPlayerService = TtsPlayerService.this;
ttsPlayerService.d.d(Boolean.valueOf(ttsPlayerService.j));
TtsPlayerService ttsPlayerService2 = TtsPlayerService.this;
ed edVar = ttsPlayerService2.c;
if (edVar != null) {
ttsPlayerService2.N(edVar, ttsPlayerService2.j);
}
}
}
class e implements View.OnClickListener {
e() {
}
@Override
public void onClick(View view) {
h hVar = TtsPlayerService.A;
if (hVar != null) {
hVar.a(false, g.g());
}
Content d = g.d();
String type = (d == null || TextUtils.isEmpty(d.getType())) ? BuildConfig.FLAVOR : d.getType();
if (TextUtils.isEmpty(type) || !type.equals("Podcast")) {
n.M(TtsPlayerService.this.getApplicationContext(), n.z2, n.m0, g.d(), BuildConfig.FLAVOR, n.d0, n.j0);
} else {
String podcastTitle = TextUtils.isEmpty(d.getPodcastTitle()) ? BuildConfig.FLAVOR : d.getPodcastTitle();
n.M(TtsPlayerService.this.getApplicationContext(), n.A2, n.m0, g.d(), BuildConfig.FLAVOR, podcastTitle);
n.M(TtsPlayerService.this.getApplicationContext(), n.k0, n.m0, g.d(), BuildConfig.FLAVOR, podcastTitle);
}
TtsPlayerService.this.M();
l.m(TtsPlayerService.this.getApplicationContext(), "runningPlayerID", BuildConfig.FLAVOR);
}
}
class f implements PlayerControlView.ProgressUpdateListener {
f() {
}
public void onProgressUpdate(long j, long j2) {
String str;
long j3 = TtsPlayerService.B;
if (0 != j3 && -9223372036854775807L != j3 && j3 > j) {
str = "-" + Util.getStringForTime(TtsPlayerService.this.s, TtsPlayerService.this.t, TtsPlayerService.B - j);
} else if (TtsPlayerService.this.o == null || -9223372036854775807L == TtsPlayerService.this.o.getDuration() || TtsPlayerService.this.o.getDuration() <= j) {
str = "00:00";
} else {
str = "-" + Util.getStringForTime(TtsPlayerService.this.s, TtsPlayerService.this.t, TtsPlayerService.this.o.getDuration() - j);
}
ed edVar = TtsPlayerService.this.c;
if (edVar != null) {
edVar.i.setText(str);
}
}
}
public void A(Boolean bool) {
Log.d("TtsPlayerService", "onAutoPause : " + bool);
ExoPlayer exoPlayer = this.o;
if (exoPlayer != null) {
boolean playWhenReady = exoPlayer.getPlayWhenReady();
this.y = playWhenReady;
if (playWhenReady) {
E(false);
}
}
}
public void B(Boolean bool) {
Log.d("TtsPlayerService", "onAutoPause : " + bool);
if (this.o != null) {
M();
l.m(getApplicationContext(), "runningPlayerID", BuildConfig.FLAVOR);
}
}
public void C(MediaMetadataCompat mediaMetadataCompat) {
F();
E(true);
}
private void D() {
r rVar = g.b;
if (rVar != null) {
if (!rVar.g().hasObservers()) {
g.b.g().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.v((Boolean) obj);
}
}));
}
if (!g.b.l().hasObservers()) {
g.b.l().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.w((Boolean) obj);
}
}));
}
if (!g.b.i().hasObservers()) {
g.b.i().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.x((Boolean) obj);
}
}));
}
if (!g.b.h().hasObservers()) {
g.b.h().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.y((Boolean) obj);
}
}));
}
if (!g.b.m().hasObservers()) {
g.b.m().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.z((Boolean) obj);
}
}));
}
if (!g.b.j().hasObservers()) {
g.b.j().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.A((Boolean) obj);
}
}));
}
if (g.b.k().hasObservers()) {
return;
}
g.b.k().observe(this, new m7.c(new m7.b() {
@Override
public final void a(Object obj) {
TtsPlayerService.this.B((Boolean) obj);
}
}));
}
}
private void E(boolean z) {
ExoPlayer exoPlayer = this.o;
if (exoPlayer != null) {
exoPlayer.setPlayWhenReady(z);
}
}
private void F() {
try {
ExoPlayer exoPlayer = this.o;
if (exoPlayer != null) {
exoPlayer.setMediaSource(g.f(getApplicationContext()));
this.o.prepare();
if (l.j(getApplicationContext(), g.g()) != 0) {
this.o.seekTo(0, l.j(getApplicationContext(), g.g()));
} else {
this.o.seekTo(0, 0L);
}
this.o.addAnalyticsListener(new m7.e(getApplicationContext(), g.d()));
}
} catch (Exception e2) {
e2.printStackTrace();
o0.f(e2);
}
}
private void G() {
E(false);
try {
MediaSessionCompat mediaSessionCompat = this.q;
if (mediaSessionCompat != null) {
mediaSessionCompat.setActive(false);
this.q.release();
this.q = null;
}
i iVar = this.p;
if (iVar != null) {
iVar.c();
this.p = null;
}
MediaSessionConnector mediaSessionConnector = this.r;
if (mediaSessionConnector != null) {
mediaSessionConnector.setPlayer((Player) null);
this.r = null;
}
ExoPlayer exoPlayer = this.o;
if (exoPlayer != null) {
exoPlayer.removeListener(this);
this.o.release();
this.o = null;
}
r rVar = g.b;
if (rVar != null) {
rVar.g().removeObservers(this);
g.b.h().removeObservers(this);
g.b.l().removeObservers(this);
g.b.i().removeObservers(this);
g.b.m().removeObservers(this);
g.b.j().removeObservers(this);
g.b.k().removeObservers(this);
}
g.l("media_root_id");
l.m(getApplicationContext(), "runningPlayerID", BuildConfig.FLAVOR);
} catch (Exception e2) {
e2.printStackTrace();
}
try {
ks0 ks0Var = this.d;
if (ks0Var != null) {
this.e.removeView(ks0Var.getRoot());
this.d = null;
}
} catch (Exception e3) {
e3.printStackTrace();
}
}
private void H() {
MediaSessionCompat mediaSessionCompat = this.q;
if (mediaSessionCompat != null) {
mediaSessionCompat.setSessionActivity(q());
}
}
private void I() {
ExoPlayer build = new ExoPlayer.Builder(getApplicationContext()).build();
this.o = build;
build.setAudioAttributes(g.b(), true);
this.o.setHandleAudioBecomingNoisy(true);
this.q = new MediaSessionCompat(getApplicationContext(), "com.htmedia.mint_article_tts");
H();
this.q.setActive(true);
setSessionToken(this.q.getSessionToken());
p();
m7.f fVar = new m7.f(new m7.d() {
@Override
public final void a(MediaMetadataCompat mediaMetadataCompat) {
TtsPlayerService.this.C(mediaMetadataCompat);
}
});
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(this.q);
this.r = mediaSessionConnector;
mediaSessionConnector.setPlayer(this.o);
this.r.setPlaybackPreparer(fVar);
this.r.setQueueNavigator(new a(this.q));
this.o.addListener(this);
this.p.d(this.o);
}
private void J() {
this.e = (WindowManager) getSystemService("window");
this.h = new DisplayMetrics();
this.g = new Point();
this.e.getDefaultDisplay().getSize(this.g);
this.e.getDefaultDisplay().getMetrics(this.h);
this.b = 2038;
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(-2, -2, this.b, 8, -3);
this.f = layoutParams;
layoutParams.gravity = 8388629;
}
private void K(boolean z) {
ks0 ks0Var = this.d;
if (ks0Var != null) {
ks0Var.b.setVisibility(z ? 8 : 0);
}
}
private void L() {
Log.d("TtsPlayerService", "Stop foreground service.");
G();
stopForeground(true);
this.u = false;
B = 0L;
stopSelf();
}
public void N(ed edVar, boolean z) {
if (z) {
if (this.i) {
edVar.c.setImageDrawable(ContextCompat.getDrawable(this, 2131234325));
edVar.h.setImageDrawable(ContextCompat.getDrawable(this, 2131234319));
edVar.i.setTextColor(-1);
edVar.g.setBufferedColor(Color.parseColor("#212121"));
edVar.g.setUnplayedColor(Color.parseColor("#212121"));
} else {
edVar.c.setImageDrawable(ContextCompat.getDrawable(this, 2131234324));
edVar.h.setImageDrawable(ContextCompat.getDrawable(this, 2131234318));
edVar.i.setTextColor(Color.parseColor("#212121"));
edVar.g.setBufferedColor(Color.parseColor("#2a000000"));
edVar.g.setUnplayedColor(Color.parseColor("#2a000000"));
}
edVar.i.setVisibility(0);
edVar.g.setVisibility(0);
edVar.f.setVisibility(8);
edVar.e.setImageDrawable(ContextCompat.getDrawable(this, 2131234333));
edVar.d.setImageDrawable(ContextCompat.getDrawable(this, 2131234331));
} else {
edVar.i.setVisibility(8);
edVar.g.setVisibility(8);
edVar.f.setTextColor(this.i ? -1 : Color.parseColor("#212121"));
edVar.f.setVisibility(0);
edVar.e.setImageDrawable(ContextCompat.getDrawable(this, 2131234334));
edVar.d.setImageDrawable(ContextCompat.getDrawable(this, 2131234332));
}
this.d.c.setShowFastForwardButton(z);
this.d.c.setShowRewindButton(z);
}
private void o() {
try {
ks0 inflate = DataBindingUtil.inflate(LayoutInflater.from(this), 2131625293, (ViewGroup) null, false);
this.d = inflate;
inflate.c(Boolean.valueOf(this.i));
this.d.d(Boolean.valueOf(this.j));
this.c = DataBindingUtil.bind(this.d.c.findViewById(2131428126));
this.d.c.setPlayer(this.o);
ed edVar = this.c;
if (edVar != null) {
N(edVar, this.j);
}
this.d.c.getPlayer().addListener(new b());
this.e.addView(this.d.getRoot(), this.f);
} catch (Exception e2) {
e2.printStackTrace();
}
}
private void p() {
this.p = new i(this, this.q.getSessionToken(), this, 2131233808);
}
private PendingIntent q() {
Intent launchIntentForPackage;
MediaMetadataCompat mediaMetadataCompat = g.a;
if (mediaMetadataCompat == null || mediaMetadataCompat.getString("android.media.metadata.STORY_LINK") == null) {
launchIntentForPackage = getPackageManager().getLaunchIntentForPackage(getPackageName());
} else {
launchIntentForPackage = new Intent(getApplicationContext(), (Class<?>) DeepLinkActivity.class);
launchIntentForPackage.setData(Uri.parse(g.a.getString("android.media.metadata.STORY_LINK")));
}
return Build.VERSION.SDK_INT >= 31 ? PendingIntent.getActivity(this, 0, launchIntentForPackage, 67108864) : PendingIntent.getActivity(this, 0, launchIntentForPackage, 134217728);
}
private void r() {
I();
this.j = false;
}
private void s() {
this.t = new Formatter(this.s, Locale.getDefault());
D();
}
@SuppressLint({"ClickableViewAccessibility"})
private void t() {
this.d.b.setOnTouchListener(new c());
this.d.d.setOnClickListener(new d());
this.d.a.setOnClickListener(new e());
this.d.c.setProgressUpdateListener(new f());
}
private void u() {
J();
this.i = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("NIGHT_MODE", false);
o();
}
public void v(Boolean bool) {
Log.d("TtsPlayerService", "appInBackground : " + bool);
this.x = bool.booleanValue();
if (this.w || this.z) {
return;
}
K(bool.booleanValue());
}
public void w(Boolean bool) {
if (bool.booleanValue()) {
this.v = false;
notifyChildrenChanged("media_root_id");
H();
}
}
public void x(Boolean bool) {
Log.d("TtsPlayerService", "interstitialAdShown : " + bool);
this.w = bool.booleanValue();
if (bool.booleanValue()) {
this.y = this.o.getPlayWhenReady();
}
if (this.y) {
E(!bool.booleanValue());
}
if (this.x || this.z) {
return;
}
K(bool.booleanValue());
}
public void y(Boolean bool) {
Log.d("TtsPlayerService", "themeChange : " + bool);
if (this.i != bool.booleanValue()) {
boolean booleanValue = bool.booleanValue();
this.i = booleanValue;
ks0 ks0Var = this.d;
if (ks0Var != null) {
ks0Var.c(Boolean.valueOf(booleanValue));
ed edVar = this.c;
if (edVar != null) {
N(edVar, this.j);
}
}
}
}
public void z(Boolean bool) {
Log.d("TtsPlayerService", "videoDetailPageShown : " + bool);
this.z = bool.booleanValue();
if (bool.booleanValue()) {
this.y = this.o.getPlayWhenReady();
}
if (this.y) {
E(!bool.booleanValue());
}
}
public void M() {
if (this.o != null) {
ks0 ks0Var = this.d;
if (ks0Var != null && ks0Var.c.getPlayer() != null && this.d.c.getPlayer().getCurrentPosition() > 0) {
l.m(getApplicationContext(), g.g(), Long.valueOf(this.d.c.getPlayer().getCurrentPosition()));
}
this.o.stop();
L();
return;
}
if (this.d.c.getPlayer() != null) {
Player player = this.d.c.getPlayer();
Objects.requireNonNull(player);
if (player.getCurrentPosition() > 0) {
l.m(getApplicationContext(), g.g(), Long.valueOf(this.d.c.getPlayer().getCurrentPosition()));
L();
}
}
l.m(getApplicationContext(), g.g(), 0);
L();
}
@NonNull
public Lifecycle getLifecycle() {
return this.a.getLifecycle();
}
public IBinder onBind(Intent intent) {
this.a.onServicePreSuperOnBind();
return super.onBind(intent);
}
public void onCreate() {
this.a.onServicePreSuperOnCreate();
super.onCreate();
r();
u();
s();
t();
}
public void onDestroy() {
this.a.onServicePreSuperOnDestroy();
Log.d("TtsPlayerService", "onDestroy");
G();
stopForeground(true);
this.u = false;
B = 0L;
l.m(getApplicationContext(), "runningPlayerID", BuildConfig.FLAVOR);
super/*android.app.Service*/.onDestroy();
}
@Nullable
public MediaBrowserServiceCompat.BrowserRoot onGetRoot(@NonNull String str, int i, @Nullable Bundle bundle) {
Log.d("TtsPlayerService", "onGetRoot");
return new MediaBrowserServiceCompat.BrowserRoot("media_root_id", (Bundle) null);
}
public void onIsPlayingChanged(boolean z) {
Log.d("TtsPlayerService", "onIsPlayingChanged " + z);
}
public void onLoadChildren(@NonNull String str, @NonNull MediaBrowserServiceCompat.Result<List<MediaBrowserCompat.MediaItem>> result) {
if ("media_root_id".equals(str)) {
Log.d("TtsPlayerService", "onLoadChildren");
result.sendResult(g.e());
if (this.v) {
return;
}
F();
E(true);
this.v = true;
}
}
public void onNotificationCancelled(int i, boolean z) {
Log.d("TtsPlayerService", "onNotificationCancelled");
L();
}
public void onNotificationPosted(int i, Notification notification, boolean z) {
if (!z || this.u) {
return;
}
try {
ContextCompat.startForegroundService(getApplicationContext(), new Intent(getApplicationContext(), (Class<?>) TtsPlayerService.class));
Log.d("TtsPlayerService", "onNotificationPosted");
startForeground(i, notification);
this.u = true;
} catch (Exception e2) {
e2.printStackTrace();
}
}
public void onPlayWhenReadyChanged(boolean z, int i) {
Log.d("TtsPlayerService", "onPlayWhenReadyChanged " + z);
}
public void onPlaybackStateChanged(int i) {
ExoPlayer exoPlayer;
if (i == 3 || i == 2) {
if (i == 3 && (exoPlayer = this.o) != null && exoPlayer.getPlayWhenReady()) {
B = this.o.getDuration();
return;
}
return;
}
if (i != 4) {
this.p.c();
} else {
L();
n4.b.E(g.d(), false, true);
}
}
public void onPlayerError(PlaybackException playbackException) {
boolean a2 = m0.a(getApplicationContext());
ToastHelper.showToast(getApplicationContext(), a2 ? "Uh.. Can't play the article right now. Please try again later" : getString(2131952314));
if (a2) {
M();
}
Log.d("TtsPlayerService", playbackException.toString());
}
public void onStart(Intent intent, int i) {
this.a.onServicePreSuperOnStart();
super/*android.app.Service*/.onStart(intent, i);
}
public int onStartCommand(@Nullable Intent intent, int i, int i2) {
return super/*android.app.Service*/.onStartCommand(intent, i, i2);
}
public void onTaskRemoved(Intent intent) {
Log.d("TtsPlayerService", "onTaskRemoved");
super/*android.app.Service*/.onTaskRemoved(intent);
M();
l.m(getApplicationContext(), "runningPlayerID", BuildConfig.FLAVOR);
}
}