如何使用jwplayer android sdk

时间:2016-03-29 16:33:10

标签: java android jwplayer

我是JWPlayer的新手。我从jwplayer获得了许可并正在进行中。我不知道如何在插播广告,前贴片广告和后贴片广告中播放广告。我也试过但是找不到任何好的资源。请指导我。我的试用期很快就会到期。提前致谢。我试过以下代码。我真的不知道如何在JWPlayer上播放广告。

public class VideoActivity extends Activity implements VideoPlayerEvents.OnFullscreenListener
    {
        JWPlayerView mPlayerView;
        private JWEventHandler mEventHandler;
        String videoUri;
        ArrayList<AdBreak> adsBreakList;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.activity_video);
            mPlayerView = (JWPlayerView)findViewById(R.id.jwplayer);
            videoUri = "http:"+getIntent().getExtras().getString("url");
            adsBreakList = new ArrayList<>();
            mPlayerView.addOnFullscreenListener(this);
            mEventHandler = new JWEventHandler(mPlayerView);

            Ad ad1 = new Ad(AdSource.VAST, videoUri);
            AdBreak ad = new AdBreak("pre", ad1);
            adsBreakList.add(ad);

            PlaylistItem pi = new PlaylistItem.Builder().file(videoUri).adSchedule(adsBreakList).build();
            mPlayerView.load(pi);
        }

2 个答案:

答案 0 :(得分:1)

以下是有关播放VAST广告,VMAP以及将其加载到Google IMA for JW Player中的文章:https://developer.jwplayer.com/sdk/android/docs/developer-guide/interaction/advertising/

此外,您可能需要查看API参考中的广告类:https://developer.jwplayer.com/sdk/android/reference/

希望这些文章有所帮助,如果没有,请随时在这里再次发表评论,或者打开JW Player的支持案例以帮助排除故障。

答案 1 :(得分:0)

使用JW播放器的预滚动,midroll广告的Android直播视频流

 public class LiveTv extends BaseActivity implements      VideoPlayerEvents.OnErrorListener{

String path = "your video stream path";
String preRoll = "http://pubads.g.doubleclick.net or any other ad url";
String midRoll = "http://pubads.g.doubleclick.net or any other ad url";
ArrayList<PlaylistItem> videosList = new ArrayList<PlaylistItem>();
private Ad ad;
private AdBreak adBreak;
private LinkedList<AdBreak> schedule;
private PlaylistItem playItem;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.livetv);
    JWPlayerFragment fragment = (JWPlayerFragment) getFragmentManager().findFragmentById(R.id.playerFragment);
    // Get a handle to the JWPlayerView
    JWPlayerView playerView = fragment.getPlayer();
    playerView.playAd(preRoll);

    ad = new Ad(AdSource.VAST, midRoll);
    adBreak = new AdBreak("10%", ad);
    schedule = new LinkedList<>();
    schedule.add(adBreak);
    playItem = new PlaylistItem.Builder()
            .file(path)
            .adSchedule(schedule) // Set the Ad Schedule
            .build();

    playerView.addOnAdErrorListener(new AdvertisingEvents.OnAdErrorListener() {
        @Override
        public void onAdError(String s, String s1) {
            Log.d("adLoaad","adload failed");
            Toast.makeText(getApplicationContext(), "Error loading ad", Toast.LENGTH_LONG).show();
        }
    });
    playerView.load(playItem);
}

@Override
public void onError(String s) {
    Toast.makeText(getApplicationContext(), "JW player Error", Toast.LENGTH_LONG).show();
}
 }