diff --git a/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java b/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java index 8016b9f36..055d72c60 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java +++ b/app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java @@ -244,7 +244,7 @@ private String getUrl() { //String url = "ijkhttphook:https://res.exexm.com/cw_145225549855002"; //String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4"; - String url = "http://hjq-1257036536.cos.ap-shanghai.myqcloud.com/m3u8/m1/video.m3u8"; + String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4"; //String url = "http://7xjmzj.com1.z0.glb.clouddn.com/20171026175005_JObCxCE2.mp4"; //String url = "http://hjq-1257036536.cos.ap-shanghai.myqcloud.com/m3u8/m1/out2.m3u8"; //String url = "http://223.110.243.138/PLTV/2510088/224/3221227177/index.m3u8"; diff --git a/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java b/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java index a5627b2c2..ca44216db 100644 --- a/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java +++ b/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java @@ -4,6 +4,7 @@ import android.content.Context; import android.net.NetworkInfo; import android.net.Uri; +import android.os.Handler; import android.os.Looper; import android.support.annotation.Nullable; import android.support.annotation.Size; @@ -165,33 +166,7 @@ public String getDataSource() { public void prepareAsync() throws IllegalStateException { if (mInternalPlayer != null) throw new IllegalStateException("can't prepare a prepared player"); - TrackSelection.Factory videoTrackSelectionFactory = - new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); - mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); - - mEventLogger = new EventLogger(mTrackSelector); - - boolean preferExtensionDecoders = true; - boolean useExtensionRenderers = true;//是否开启扩展 - @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = useExtensionRenderers - ? (preferExtensionDecoders ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER - : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON) - : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF; - - rendererFactory = new DefaultRenderersFactory(mAppContext, extensionRendererMode); - DefaultLoadControl loadControl = new DefaultLoadControl(); - mInternalPlayer = ExoPlayerFactory.newSimpleInstance(mAppContext, rendererFactory, mTrackSelector, loadControl, null, Looper.getMainLooper()); - mInternalPlayer.addListener(this); - mInternalPlayer.addAnalyticsListener(this); - mInternalPlayer.addListener(mEventLogger); - if (mSpeedPlaybackParameters != null) { - mInternalPlayer.setPlaybackParameters(mSpeedPlaybackParameters); - } - if (mSurface != null) - mInternalPlayer.setVideoSurface(mSurface); - - mInternalPlayer.prepare(mMediaSource); - mInternalPlayer.setPlayWhenReady(false); + prepareAsyncInternal(); } @Override @@ -357,6 +332,39 @@ public void release() { } } + protected void prepareAsyncInternal() { + new Handler(Looper.getMainLooper()).post( + new Runnable() { + @Override + public void run() { + mTrackSelector = new DefaultTrackSelector(); + mEventLogger = new EventLogger(mTrackSelector); + boolean preferExtensionDecoders = true; + boolean useExtensionRenderers = true;//是否开启扩展 + @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = useExtensionRenderers + ? (preferExtensionDecoders ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER + : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON) + : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF; + + rendererFactory = new DefaultRenderersFactory(mAppContext, extensionRendererMode); + DefaultLoadControl loadControl = new DefaultLoadControl(); + mInternalPlayer = ExoPlayerFactory.newSimpleInstance(mAppContext, rendererFactory, mTrackSelector, loadControl, null, Looper.getMainLooper()); + mInternalPlayer.addListener(IjkExo2MediaPlayer.this); + mInternalPlayer.addAnalyticsListener(IjkExo2MediaPlayer.this); + mInternalPlayer.addListener(mEventLogger); + if (mSpeedPlaybackParameters != null) { + mInternalPlayer.setPlaybackParameters(mSpeedPlaybackParameters); + } + if (mSurface != null) + mInternalPlayer.setVideoSurface(mSurface); + + mInternalPlayer.prepare(mMediaSource); + mInternalPlayer.setPlayWhenReady(false); + } + } + ); + } + public void stopPlayback() { mInternalPlayer.stop(); } @@ -441,7 +449,6 @@ public int getBufferedPercentage() { } - @Override public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {