AdMediaModel.java


Overview

The [AdMediaModel.java](/projects/288/68370) file defines the `AdMediaModel` class, which serves as a container for managing a collection of advertisement media items (`MediaModel` instances). It encapsulates a list of ads typically representing an **Ad Break**—a sequence of advertisements to be played together during media playback.

This class provides utility methods to:

By abstracting the ad break concept, `AdMediaModel` simplifies the ad playback logic within the media player system, enabling orderly consumption of ads during preroll, midroll, or postroll ad breaks.


Class: AdMediaModel

public class AdMediaModel {
    private List<MediaModel> listOfAds;

    public AdMediaModel(@NonNull List<MediaModel> listOfAds) { ... }

    @Nullable
    public MediaModel nextAD() { ... }

    public List<MediaModel> getListOfAds() { ... }

    public void popFirstAd() { ... }

    public int nubmerOfAd() { ... }
}

Description

`AdMediaModel` wraps a list of `MediaModel` objects, each representing a single ad. It is primarily used to represent an **Ad Break**, which contains multiple ads to be played sequentially.


Fields

Field

Type

Description

`listOfAds`

`List`

The list of ads in this Ad Break (may be empty).


Constructors

AdMediaModel(List<MediaModel> listOfAds)

**Example:**

List<MediaModel> ads = new ArrayList<>();
ads.add(MediaModel.ad("http://example.com/ad1.m3u8", "http://advertiser.com", false));
ads.add(MediaModel.ad("http://example.com/ad2.m3u8", null, false));

AdMediaModel adBreak = new AdMediaModel(ads);

Methods

@Nullable MediaModel nextAD()

**Usage Example:**

MediaModel nextAd = adBreak.nextAD();
if (nextAd != null) {
    // Prepare to play nextAd
}

List<MediaModel> getListOfAds()


void popFirstAd()

**Usage Example:**

// After playing the current ad
adBreak.popFirstAd();

int nubmerOfAd()

**Note:** There is a minor typo in the method name; it should ideally be `numberOfAd()` for clarity.

**Usage Example:**

int remainingAds = adBreak.nubmerOfAd();

Important Implementation Details


Interaction with Other System Components


Usage Scenario Example

// Assume adList is fetched or constructed elsewhere
AdMediaModel adBreak = new AdMediaModel(adList);

while (adBreak.nubmerOfAd() > 0) {
    MediaModel currentAd = adBreak.nextAD();
    if (currentAd != null) {
        playAd(currentAd);  // Method to play the ad
        adBreak.popFirstAd();
    }
}

Class Diagram

classDiagram
    class AdMediaModel {
        - List~MediaModel~ listOfAds
        + AdMediaModel(listOfAds)
        + nextAD() MediaModel
        + getListOfAds() List~MediaModel~
        + popFirstAd() void
        + nubmerOfAd() int
    }

    class MediaModel {
        <<external>>
    }

    AdMediaModel "1" --> "*" MediaModel : contains >

Summary

`AdMediaModel` is a simple yet crucial class that models an ad break as a list of ads (`MediaModel` objects). It provides methods to access and consume ads sequentially, enabling the media player to manage ad playback cleanly and efficiently. Its integration with other playback components ensures smooth transitions between content and ads, supporting features like midrolls and prerolls in the overall media playback workflow.


End of AdMediaModel.java Documentation