Я не знаю, поддерживает ли exoplayer файл .m3u8 или нет, но он показывает эту ошибку в logcat.
Я получаю ссылки из firebase, у которой есть .m3u8, например
https://pubads.g.doubleclick.net/ssai/event/fi5oKDz-RnC4XnNBHtxvOQ/master.m3u8
Моя ошибка фильтрации Logcat ...
2020-08-04 11:40:34.606 6199-6477/com.wordpress.myselfnikunj.mytv E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor) could read the stream.
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:924)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:846)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:308)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Вот мой exoPlayer. java
package com.wordpress.myselfnikunj.mytv;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import static android.view.View.GONE;
public class ExoPlayerActivity extends AppCompatActivity {
//Initialize variable
PlayerView playerView;
ProgressBar progressBar;
ImageView btFullScreen;
SimpleExoPlayer simpleExoPlayer;
boolean flag = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exo_player);
//Assign variable
playerView = findViewById(R.id.playerView);
progressBar = findViewById(R.id.progress_bar);
btFullScreen = findViewById(R.id.bt_fullscreen);
//Make activity full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//VideoUrl
Intent intent = getIntent();
String link = intent.getStringExtra("link");
Uri videoUrl = Uri.parse(link);
//Initialize load control
LoadControl loadControl = new DefaultLoadControl();
//Initialize band width meter
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
//Initialize track selector
TrackSelector trackSelector = new DefaultTrackSelector(
new AdaptiveTrackSelection.Factory(bandwidthMeter)
);
//Initialize simple exo player
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(
this,trackSelector,loadControl
);
//Initialize data source factory
DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory(
"exoplayer_video"
);
//Initialize extractors factory
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
//Initialize media source
MediaSource mediaSource = new ExtractorMediaSource(videoUrl
,factory,extractorsFactory,null,null);
//Set player
playerView.setPlayer(simpleExoPlayer);
//Keep screen on
playerView.setKeepScreenOn(true);
//Prepare media
simpleExoPlayer.prepare(mediaSource);
//Play video when ready
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.addListener(new Player.EventListener() {
@Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
@Override
public void onLoadingChanged(boolean isLoading) {
}
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
//Check condition
if (playbackState == Player.STATE_BUFFERING) {
//When Buffering
//Show progress Bar
progressBar.setVisibility(View.VISIBLE);
} else if (playbackState == Player.STATE_READY) {
//When ready
//Hide progress bar
progressBar.setVisibility(GONE);
}
}
@Override
public void onRepeatModeChanged(int repeatMode) {
}
@Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}
@Override
public void onPlayerError(ExoPlaybackException error) {
}
@Override
public void onPositionDiscontinuity(int reason) {
}
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
@Override
public void onSeekProcessed() {
}
});
btFullScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Check condition
if (flag) {
//When flag is true
//Set enter full screen image
btFullScreen.setImageDrawable(getResources()
.getDrawable(R.drawable.ic_fullscreen));
//Set potrait orientation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//Set flag value as false
flag = false;
} else {
//When flag is false
//Set exit full screen image
btFullScreen.setImageDrawable(getResources()
.getDrawable(R.drawable.ic_fullscreen_exit));
//Set potrait orientation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//Set flag value as true
flag = true;
}
}
});
}
@Override
protected void onPause() {
super.onPause();
//Stop video when ready
simpleExoPlayer.setPlayWhenReady(false);
//Get playback state
simpleExoPlayer.getPlaybackState();
}
@Override
protected void onRestart() {
super.onRestart();
//Play video when ready
simpleExoPlayer.setPlayWhenReady(true);
//Get playback state
simpleExoPlayer.getPlaybackState();
}
}
***
My XML file
***
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ExoPlayerActivity">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
app:controller_layout_id="@layout/custom_controller"
app:fastforward_increment="10000"
app:hide_on_touch="true"
app:player_layout_id="@layout/exo_simple_player_view"
app:resize_mode="fit"
app:rewind_increment="10000"
app:show_timeout="5000"
app:use_controller="true" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
ВЫ ЭТО МОЖНО ПРОПУСТИТЬ, ПОСКОЛЬКУ ВИДЕО НЕ ЗАГРУЖАЕТСЯ ... ДИЗАЙН НЕ ВАЖЕН В ВЫПУСКЕ ЗДЕСЬ Я ТАК ДУМАЮ ...
Мой пользовательский контроллер. xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/exo_rew"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_rew"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/exo_play"
android:src="@drawable/ic_play"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/exo_pause"
android:src="@drawable/ic_pause"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/exo_ffwd"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_ffwd"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:id="@+id/exo_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:text="/"
android:textColor="#CBCDC8" />
<TextView
android:id="@+id/exo_duration"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#CBCDC8" />
<ImageView
android:id="@+id/bt_fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_fullscreen" />
</LinearLayout>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@+id/exo_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-8dp"
app:buffered_color="#95989F"
app:played_color="#FF0000"
app:unplayed_color="#45424E" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>