Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide FixedAdsLoader to play ads from URLs known in advance #4680

Open
hafiz013 opened this issue Aug 20, 2018 · 10 comments
Open

Provide FixedAdsLoader to play ads from URLs known in advance #4680

hafiz013 opened this issue Aug 20, 2018 · 10 comments

Comments

@hafiz013
Copy link

I found out that someone post about how to play ads locally through this link https://github.com/google/ExoPlayer/issues/3664 . However, it not show the code in details how to implement ads loader without ima extension. As solution, I found this link helpfully to use https://www.programcreek.com/java-api-examples/?code=googleads/googleads-ima-android/googleads-ima-android-master/BasicExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java and this link to play ads multline (meaning that every 30 seconds play the ads) https://stackoverflow.com/questions/49871348/how-to-show-ads-at-specific-points-using-exoplayers-ima-extension. If someone know how to customize adsloader without ima extension please share the code. Thank you.

@andrewlewis andrewlewis self-assigned this Aug 20, 2018
@andrewlewis
Copy link
Collaborator

We don't have any sample code for that at the moment, apart from the snippets @marcbaechinger has already provided in the Stack Overflow answer and #3664. It's probably a lot more complicated than what you need, but you could try using the source for ImaAdsLoader as a starting point then modify it to include your own information about ads and simplify it.

I'll use this issue to track implementing something like a FixedAdsLoader that easily lets you play ads from given URLs known in advance. Once that is done, you may be able to use it directly or as a starting point for what you need to do.

@hafiz013
Copy link
Author

Ok i give more clear code for those new about this but still not working.

  1. first create bandwidth
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

  2. create load control and datasourcefactory
    `LoadControl loadControl = new DefaultLoadControl();
    //new DefaultTrackSelector(), new DefaultLoadControl()
    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(context), trackSelector, loadControl);//trackSelector, loadControl);

     DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
             Util.getUserAgent(context, "mediaPlayerSample"), (TransferListener<? super DataSource>) bandwidthMeter);`
    
  3. create media source content
    mVideoSource = new ExtractorMediaSource.Factory(dataSourceFactory).setExtractorsFactory (newDefaultExtractorsFactory()).createMediaSource(Uri.parse(pathVideo));`

  4. last create mediasource with ads

` mediaSourceWithAds =
new AdsMediaSource(mVideoSource,
dataSourceFactory, new AdsLoader() {
@OverRide
public void setSupportedContentTypes(int... contentTypes) {

                }

                @Override
                public void attachPlayer(ExoPlayer player, EventListener eventListener, ViewGroup adUiViewGroup) {
                    Log.e("videAds", "yeah");
                    ///storage/emulated/0/AdsFolder/mcd.mp4
                    //addgroup = new AdPlaybackState.AdGroup();
                    //addgroup.count, 30 * C.MICROS_PER_SECOND
                    adPlaybackState = new AdPlaybackState( 30 * C.MICROS_PER_SECOND);

                    for (int i = 0; i < listOfFiles.length; i++) {
                        Log.e("file:", pathVideo+"/"+listOfFiles[i].getName());
                        if (listOfFiles[i].isFile()) {
                            //addgroup.withAdUri(Uri.parse(pathAds+"/"+listOfFiles[i].getName()), i);
                         // loop file local to play video ads instead of online video ads
                            adPlaybackState.withAdUri()
                        }
                    }

                    eventListener.onAdPlaybackState(adPlaybackState);

                    player.addListener(ViewVideo.this);
                }

                @Override
                public void detachPlayer() {

                }

                @Override
                public void release() {

                }

                @Override
                public void handlePrepareError(int adGroupIndex, int adIndexInAdGroup, IOException e) {
                    Log.e("handlePrepareError", e.toString());
                }
            }, videoView.getOverlayFrameLayout());`
  1. set prepare

exoPlayer.prepare(mediaSourceWithAds); //exoPlayer.setPlayWhenReady(true); videoView.setPlayer(exoPlayer);

however, in time 30 seconds, ads not load from local phone folder. the current video stop until end and not play again.

@arukesari
Copy link

arukesari commented Sep 28, 2018

Any updates on this? I am also facing similar issue. I followed the link : https://stackoverflow.com/questions/49871348/how-to-show-ads-at-specific-points-using-exoplayers-ima-extension

However it is not even playing main content video.I also trying creating Media source containing preroll and main content using ConcatenatingMediaSource and passed this source to AdsMediaSource
Player shows video is buffering and is stuck there and no exceptions in logs.
I am trying to integrate Freewheel Ads with Exoplayer and don't want to do the player swap.

@ojw28 ojw28 changed the title how to play AdsLoader without ima extension Provide FixedAdsLoader to play ads from URLs known in advance Apr 5, 2019
@hafiz013
Copy link
Author

Since this issue was closed but not yet implement in current version 2.9.6. May I know when u will take this as enhancement also.

@andrewlewis
Copy link
Collaborator

@hafiz013 This enhancement is still open but we are currently treating it as a low priority, and don't have an ETA for it.

@hafiz013
Copy link
Author

Ok note thanks

@ibraizQazi
Copy link

Any updates or guideline to implement a simple custom AdsLoader?

@andrewlewis
Copy link
Collaborator

No updates I'm afraid.

@CristianMG
Copy link

There are any new about this? We need show ads pre mid and post roll.

@andrewlewis
Copy link
Collaborator

We are still treating this as a low priority, I'm afraid. I'll update this issue if/when we get round to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants