# Override play insert Midroll

**URL:** <https://community.wowza.com/t/override-play-insert-midroll/241>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [December 2, 2009, 7:01pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241 "2009-12-02T19:01:47Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![sam\_ola](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_ola](https://community.wowza.com/u/sam_ola)\
**Post date:** [December 24, 2009, 4:40pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/21 "2009-12-24T16:40:36Z")

</div>

> stream.setName(streamName, streamExt, stream.getExt(), queryStr, 0, -1, -1);
> 
> Richard

Hi Richard,

I am getting this error "

**The method setName(String, String, String, double, double, int) in the type IMediaStream is not applicable for the arguments (String, String, String, String, int, int, int) ModuleInsertMidRoll/src/com/wowza/com/wowza/ModuleInsertMidRoll ModuleInsertMidRoll.java line 95**

**" when I try to compile this.**

**Thanks.**

---

<div class="post-metadata">

**Author:** ![sam\_ola](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_ola](https://community.wowza.com/u/sam_ola)\
**Post date:** [January 8, 2010, 9:06pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/22 "2010-01-08T21:06:01Z")

</div>

Hi Richard,

I finally was able to compile this. I copied same into live WMS and added below into Application.xml /Properties

MidRoll

Extremists.flv

FeatureBreak

10000

Nothing seems to be showing as as Roll Over Ads. Is there are other thing that I needed to do?

Thanks.

---

<div class="post-metadata">

**Author:** ![sam\_ola](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_ola](https://community.wowza.com/u/sam_ola)\
**Post date:** [January 8, 2010, 9:19pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/23 "2010-01-08T21:19:06Z")

</div>

I was thinking that “Extremists.flv” would show as a Roll Over “Ads” in which application the following property/properties are inserted.

"

MidRoll

Extremists.flv

FeatureBreak

10000

"

Thanks.

---

<div class="post-metadata">

**Author:** ![sam\_ola](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_ola](https://community.wowza.com/u/sam_ola)\
**Post date:** [January 8, 2010, 9:44pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/24 "2010-01-08T21:44:15Z")

</div>

May be am doing this wrongly. I am trying to use this with the “Server listener that starts streams with playlists and schedules from smil file”. So what I did was to add the "

MidRoll

Extremists.flv

FeatureBreak

10000

"

to the application.xml am using in this case a live stream and thought that “Extremists.flv” would play as a Roll Over at FeatureBreak. But from what you said above it seems that is not how this works. Correct?

Thanks.

---

<div class="post-metadata">

**Author:** ![sam\_ola](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_ola](https://community.wowza.com/u/sam_ola)\
**Post date:** [January 8, 2010, 10:15pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/25 "2010-01-08T22:15:04Z")

</div>

Thanks got that picture better now. So with the “Stream controller example” you pointed to, could that be in the form of using the Stream class scheduler to play a stream for xxx of time, the plays for say 30 mins and then the scheduler continues the stream after the 30mins. The AdvertRoll would have played for say 20secs before reverting back to the next file or continue from where/when it stopped. This is the only way that came to my mind now perhaps you have better suggestion.

What I mean is this

\*\*

I can understand the -1 here i.e. play to the end of the file

What should be lenght for (the first one on the list). Can it be specied that it should play for say 20 mins and the the Rolloveradvert plays and then back again to the next of previous file?

Thanks

---

<div class="post-metadata">

**Author:** ![sam\_ola](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_ola](https://community.wowza.com/u/sam_ola)\
**Post date:** [January 8, 2010, 11:22pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/26 "2010-01-08T23:22:21Z")

</div>

I see.

Many thanks

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 5:59am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/27 "2009-12-22T05:59:28Z")

</div>

Hi Richard,

I am experiencing some troubles making it work. My goal is to insert an ad at the beginning of a requested video.

So here is my code:

```auto
String stream_name = params.getString(PARAM1);
System.out.println("Inserting ad for stream: " + stream_name);
AMFDataList custom_data_list = new AMFDataList();

// The ad
custom_data_list.add("play");
custom_data_list.add(0.0);
custom_data_list.add("null");
custom_data_list.add("mp4:/uploads/medias/advert.mp4");
custom_data_list.add(new AMFDataItem(0)); // start
custom_data_list.add(new AMFDataItem(20)); //duration
custom_data_list.add(new AMFDataItem(true)); //reset
invokePrevious(this, client, function, custom_data_list);

// The movie
custom_data_list.set(PARAM1, new AMFDataItem(stream_name));
custom_data_list.set(PARAM2, new AMFDataItem(0));
custom_data_list.set(PARAM3, new AMFDataItem(-1));
custom_data_list.set(PARAM4, new AMFDataItem(false));
invokePrevious(this, client, function, custom_data_list);

```

The problem is that my ad does not play, the movie immediately plays.

If I remove the movie section, the ad alone plays.

Can you explain a little what the options are for, I don’t really understand the physics here.

Thanks

EDIT: by the way I also implemented IMediaStreamFileMapper#streamFileForRead, maybe that’s why the movie immediately starts playing?

EDIT2: is it possible to prevent users from scrubbing the timeline while watching the ad?

EDIT3: actually for my ad to play, I must specify a duration of -1 otherwise it will not play at all (even when defined alone with no movie following), why is that? Why can you define a duration and not me???

EDIT4: Richard is your system compatible with a player like Flowplayer? Or should I code my own player? I suspect Flowplayer to stop playing after the ad is finished, so it doesn’t move on to the movie that follows.

EDIT5: ok I got it working in Flowplayer, one must set the live option to true so that it carries on.

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 8:54am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/28 "2009-12-22T08:54:41Z")

</div>

Hi Richard,

When wowza switches from one video to another, is an event (or something else) dispatched to the client?

I’d like to be able to deactivate the timeline when an ad plays, and then reactivate it when the movie resumes. On the client side I need to detect these switches.

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 9:44am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/29 "2009-12-22T09:44:54Z")

</div>

I’m definitely having a problem when I specify a duration for a video, it simply does not play, and it gets skipped to the next video that has a duration of “-1”, i.e: play until the end.

What’s wrong?

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 11:56am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/30 "2009-12-22T11:56:10Z")

</div>

In order to notify the client of switched stream I tried using the following method call:

```auto
stream.send("switch_movie");

```

1. I’m not sure the call was dispatched by wowza

2. If the call was dispatched how to intercept it on the client side?

EDIT: it didn’t get called, because calling stream.close() inside this play method does not close the stream as expected. So how to do that?

EDIT2: actually I cannot notify the client from within this play method, I need to use another trick.

EDIT: I am trying to implement the seek method so that I can block seeking on the server-side which is even better!

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 3:26pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/31 "2009-12-22T15:26:13Z")

</div>

The slash doesn’t seem to be a problem, it works the same whether the slash is there or not. Did you test for the duration issue? I still cannot tell Wowza to play a video for a limited amount of time, only a duration of -1 will let the video play ☹

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 3:49pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/32 "2009-12-22T15:49:08Z")

</div>

While I’m at it, is it possible to know which item of the ‘playlist’ is currently playing?

Let’s say client requests a stream called: Matrix4.mp4

The server would inject an ad at the beginning: wowza\_ad.mp4

Now the stream is playing and it’s currently in the middle of the ad, and the client wants to seek past the ad, hmmm no good. So in my seek() method is it possible for the server to know that it’s currently playing the wowza\_ad.mp4 file and that it should not let the client seek?

At first I was trying to get the stream name, but it’s a wrong approach as it always returns “Matrix4.mp4” whether it’s currently playing the ad or not.

Thanks for any suggestion 🙂

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 4:06pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/33 "2009-12-22T16:06:17Z")

</div>

Yes, but in order to completely prevent evil users from bypassing the ads, on the server I must be able to deactivate the seeking feature when the current video being played is an ad. So how to identify ads when they are being played 😕

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 22, 2009, 4:51pm UTC](https://community.wowza.com/t/override-play-insert-midroll/241/34 "2009-12-22T16:51:02Z")

</div>

Ok I was able to retrieve the current video being played, so my anti seek system is now working.

So back to my last questions:

1. Were you able to reproduce my duration problem?

2. When injecting ads to my movie, the duration is now incorrectly reported, is it possible to return to flowplayer (or whatever player) the new total duration, i.e: movie\_duration + ∑advert\_durations ?

Thanks for your invaluable help 🆒

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 23, 2009, 8:23am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/35 "2009-12-23T08:23:25Z")

</div>

Richard! How didn’t we spot such a stupid mistake! The duration is in MILLIseconds! So a value of 10, was 10ms, no wonder why I couldn’t see the movie play! 😛

I was cracked up when I realized that!

And about notifying the player about the correct total duration, do you have any idea how to do that? Once I think I encountered something like that, but I can’t find it anymore.

---

<div class="post-metadata">

**Author:** ![aze\_aze](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aze\_aze](https://community.wowza.com/u/aze_aze)\
**Post date:** [December 24, 2009, 4:43am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/36 "2009-12-24T04:43:57Z")

</div>

Thanks Richard for your snippet of code, and merry Xmas 🙂

---

<div class="post-metadata">

**Author:** ![no\_no](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@no\_no](https://community.wowza.com/u/no_no)\
**Post date:** [March 27, 2010, 8:38am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/37 "2010-03-27T08:38:12Z")

</div>

Does it work with Cupertino streaming? I tested codes above for Flash player and it’s working just fine. But it doesn’t seem to work with iPhone

---

<div class="post-metadata">

**Author:** ![Deleze\_Deleze](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@Deleze\_Deleze](https://community.wowza.com/u/Deleze_Deleze)\
**Post date:** [August 6, 2010, 8:53am UTC](https://community.wowza.com/t/override-play-insert-midroll/241/38 "2010-08-06T08:53:52Z")

</div>

> Updated [post](http://community.wowza.com/t/-/241) for calculated duration.
> 
> Richard

Hi Richard,

In the play() method, you don’t have a reference to the stream to set the property “overrideDuration”. This can be done in the “onStreamCreate” method:

```auto
public void onStreamCreate(IMediaStream aMediaStream) 

```

And it works!

Olivier

[Previous page](https://community.wowza.com/t/override-play-insert-midroll/241.md?page=1)
