我的MainActivity.java:
PlayerView exoPlayerView;
SimpleExoPlayer exoPlayer;
String url="https://drive.google.com/file/d/1sAQsndXPmqaEPUKAaCmz9N6cnosJ0StE/preview";
String url="http://blueappsoftware.in/layout_design_android_blog.mp4";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
exoPlayerView=findViewById(R.id.exoPlayerView);
try{
BandwidthMeter bandwidthMeter=new DefaultBandwidthMeter();
TrackSelector trackSelector=new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer= ExoPlayerFactory.newSimpleInstance(this,trackSelector);
Uri videoUri=Uri.parse(url);
DefaultHttpDataSourceFactory dataSourceFactory=new DefaultHttpDataSourceFactory("ExoPlayerVideo");
ExtractorMediaSource mediaSource=new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(videoUri);
exoPlayerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
}
catch (Exception e){
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
}}
我尝试过使用exoplayer查看来自网址的视频。虽然博客网址对于相同的代码工作正常,但它不是来自谷歌驱动器链接的流视频,尽管它们是公开的。正如您在我的代码片段中看到的那样,只要您有网址,就可以从任何浏览器轻松查看网址。 在exoplayer中是否有任何解决方案,或者我必须使用其他任何内容来流式传输视频?
我收到的加载视频的错误是:
来源错误。
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor) could read the stream.
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:931)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:853)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)