Null pointer exception when used extension ima
Issue description
Null pointer exception
Reproduction steps
Added implementation 'com.google.android.exoplayer:extension-ima:2.9.0'
Link to test content
No link available
Version of ExoPlayer being used
implementation 'com.google.android.exoplayer:exoplayer:2.9.0' implementation 'com.google.android.exoplayer:extension-ima:2.9.0'
Device(s) and version(s) of Android being used
I tested only on mi a5 and version 8
A full bug report captured from the device
Process: com.recipe.filmrise, PID: 10340 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.exoplayer2.source.ads.AdsMediaSource$ComponentListener.release()' on a null object reference at com.google.android.exoplayer2.source.ads.AdsMediaSource.releaseSourceInternal(AdsMediaSource.java:391) at com.google.android.exoplayer2.source.BaseMediaSource.releaseSource(BaseMediaSource.java:165) at com.google.android.exoplayer2.ext.ima.ImaAdsMediaSource.releaseSourceInternal(ImaAdsMediaSource.java:105) at com.google.android.exoplayer2.source.BaseMediaSource.releaseSource(BaseMediaSource.java:165) at com.google.android.exoplayer2.source.CompositeMediaSource.releaseSourceInternal(CompositeMediaSource.java:70) at com.google.android.exoplayer2.source.ConcatenatingMediaSource.releaseSourceInternal(ConcatenatingMediaSource.java:509) at com.google.android.exoplayer2.source.BaseMediaSource.releaseSource(BaseMediaSource.java:165) at com.google.android.exoplayer2.ExoPlayerImplInternal.resetInternal(ExoPlayerImplInternal.java:815) at com.google.android.exoplayer2.ExoPlayerImplInternal.stopInternal(ExoPlayerImplInternal.java:734) at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:358) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:172) at android.os.HandlerThread.run(HandlerThread.java:65)
Couple of questions on this.
-
Are you calling
prepareSourceInternalorreleaseSourceInternalon the ads media source yourself? Currently if release is called before prepare is called (or finished presumably) you could probably cause this. -
Are you using
ImaAdsMediaSource? If so, it has been deprecated in favor or usingAdsMediaSourcewithImaAdsLoader
Submitted a small PR https://github.com/google/ExoPlayer/pull/4974 to add a null check to the release method.
Yes I am using below is my code imaAdsLoader = new ImaAdsLoader(this, Uri.parse(getResources().getString(R.string.ad_tag_url)));
//Creating Video Content Media Source With Ads
ImaAdsMediaSource contentMediaSourceWithAds = new ImaAdsMediaSource(
mergedSource,//Video Content Media Source
new DefaultDataSourceFactory(this, Util.getUserAgent(MediaPlayerActivity.this, "videoApp")),
imaAdsLoader,
playerView.getOverlayFrameLayout());//Overlay During Ads Playback
//return media source with ads
return contentMediaSourceWithAds;
Please provide me any link for documentation, where I can learn: How to play preroll ads How to play midroll ads How to play multiple ads one after other
changed code ImaAdsMediaSource to AdsMediaSource , but again got:
2018-10-17 16:56:05.514 10340-10626/? E/AndroidRuntime: FATAL EXCEPTION: ExoPlayerImplInternal:Handler Process: com.recipe.filmrise, PID: 10340 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.exoplayer2.source.ads.AdsMediaSource$ComponentListener.release()' on a null object reference at com.google.android.exoplayer2.source.ads.AdsMediaSource.releaseSourceInternal(AdsMediaSource.java:391) at com.google.android.exoplayer2.source.BaseMediaSource.releaseSource(BaseMediaSource.java:165) at com.google.android.exoplayer2.ext.ima.ImaAdsMediaSource.releaseSourceInternal(ImaAdsMediaSource.java:105) at com.google.android.exoplayer2.source.BaseMediaSource.releaseSource(BaseMediaSource.java:165) at com.google.android.exoplayer2.source.CompositeMediaSource.releaseSourceInternal(CompositeMediaSource.java:70) at com.google.android.exoplayer2.source.ConcatenatingMediaSource.releaseSourceInternal(ConcatenatingMediaSource.java:509) at com.google.android.exoplayer2.source.BaseMediaSource.releaseSource(BaseMediaSource.java:165) at com.google.android.exoplayer2.ExoPlayerImplInternal.resetInternal(ExoPlayerImplInternal.java:815) at com.google.android.exoplayer2.ExoPlayerImplInternal.stopInternal(ExoPlayerImplInternal.java:734) at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:358) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:172) at android.os.HandlerThread.run(HandlerThread.java:65) 2018-10-17 16:57:23.768 10952-11066/? E/AndroidRuntime: FATAL EXCEPTION: ExoPlayerImplInternal:Handler
Have you seen this blog post? https://medium.com/google-exoplayer/playing-ads-with-exoplayer-and-ima-868dfd767ea
yes I have seen that and did same. code ftom blog: MediaSource mediaSourceWithAds = new ImaAdsMediaSource( getContentMediaSource(), dataSourceFactory, imaAdsLoader, simpleExoPlayerView.getOverlayFrameLayout()); simpleExoPlayer.seekTo(contentPosition); simpleExoPlayer.prepare(mediaSource);
why does he has used mediasource instead of mediaSourceWithAds simpleExoPlayer.prepare(mediaSource);
I'm guessing that is a typo. Within the ExoPlayer repo, take a look at the ima project within the demos package. In there you can find PlayerManager that should show you how to use the Ima Extension.
It is ok , this might be typo ,but I am using media source with ads . Why does this exception is thrown. This blog does not contain any information about preroll,midroll and podsize. Please tell me how can I fix this issue
On Wed 17 Oct, 2018, 11:13 PM Brandon Davis, [email protected] wrote:
I'm guessing that is a typo. Within the ExoPlayer repo, take a look at the ima project within the demos package. In there you can find PlayerManager that should show you how to use the Ima Extension.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/ExoPlayer/issues/4973#issuecomment-430721947, or mute the thread https://github.com/notifications/unsubscribe-auth/AdgNFkKIdy_QXoJNnKx339IB-MtB5GLtks5ul2wwgaJpZM4XjyM6 .
Thanks it worked for me now, but problem is it shows ads when I pause video. When I play recently watched movie (video starts from position ,where I have left it ), App crashes How can I show midroll ads
@andrewlewis - Didn't really look at this, but as a tangential point we should probably fix the blog post :)
How can I do request for ads manually.
On Thu 18 Oct, 2018, 6:37 PM ojw28, [email protected] wrote:
@andrewlewis https://github.com/andrewlewis - Didn't really look at this, but as a tangential point we should probably fix the blog post :)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/ExoPlayer/issues/4973#issuecomment-431001055, or mute the thread https://github.com/notifications/unsubscribe-auth/AdgNFsfJ6fuT-XdLMPPMAAAcRX33mdBcks5umH0rgaJpZM4XjyM6 .
I've updated the blog post -- thanks for pointing this out!
@ummerakbar45 Please could you provide a stack trace for the latest crash?
You can request ads manually before preparing the player by calling ImaAdsLoader.requestAds. (If that method isn't called, ads are requested when the player is attached to the ads loader.)
Closing due to inactivity.