# Set duration to RTMP MP3 Streaming

**URL:** <https://community.wowza.com/t/set-duration-to-rtmp-mp3-streaming/40637>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [June 19, 2013, 5:57pm UTC](https://community.wowza.com/t/set-duration-to-rtmp-mp3-streaming/40637 "2013-06-19T17:57:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HF\_Cheung](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@HF\_Cheung](https://community.wowza.com/u/HF_Cheung)\
**Post date:** [June 19, 2013, 5:57pm UTC](https://community.wowza.com/t/set-duration-to-rtmp-mp3-streaming/40637/1 "2013-06-19T17:57:03Z")

</div>

I’ve tried the following code for MP3 streaming on RTMP, I could successfully set the play start time and duration of the MP3 file.

For example, if start time is set to 10s and duration is set to 30s, the JW Player will start playing at 10s (JW Player will display 0s) and keep playing for 30s.

But the problem is that the JW Player will just always show the whole duration of the MP3 file which is 24m00s.

How can the correct duration be displayed on JW player? Does anyone have any experience on it?

Thanks a lot!!

```auto
public class MediaReaderMP3InjectMetadata extends MediaReaderMP3{ 
	public List<ByteBuffer> getMetadata()
	{
 		List<ByteBuffer> ret = super.getMetadata();
		WMSLogger getLogger = WMSLoggerFactory.getLogger(null);
		// Here the calculated duration stored by above is extracted.
		// Note that the default duration is used if there is no duration property in the stream, so simple video streaming will work as usual
		double overrideDuration = this.stream.getProperties().getPropertyDouble("overrideDuration", (double) this.duration / 1000); // Value in seconds.
		getLogger.info("overrideDuration: " + overrideDuration);
        while(true){ 
            if (ret == null) 
                break; 
            if (ret.size() <= 0) 
                break;             
            ByteBuffer packet = ret.get(0);             
            AMFDataList myMetadata = new AMFDataList(packet); 
            AMFDataMixedArray dataObj = (AMFDataMixedArray)myMetadata.get(1); 
            dataObj.put("duration", new AMFDataItem(overrideDuration)); // duration in seconds. 
            byte[] data = myMetadata.serialize(); 
            ByteBuffer newPacket = ByteBuffer.wrap(data);             
            ret.set(0, newPacket); 
            break; 
        } 
         
		return ret;
	}

```

---

<div class="post-metadata">

**Author:** ![HF\_Cheung](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@HF\_Cheung](https://community.wowza.com/u/HF_Cheung)\
**Post date:** [June 19, 2013, 6:03pm UTC](https://community.wowza.com/t/set-duration-to-rtmp-mp3-streaming/40637/2 "2013-06-19T18:03:34Z")

</div>

The code is working fine for MP4 but not MP3.

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [June 19, 2013, 10:35am UTC](https://community.wowza.com/t/set-duration-to-rtmp-mp3-streaming/40637/3 "2013-06-19T10:35:15Z")

</div>

This might help. Add these Property settings to the Application.xml /MediaReader Properties container:

```auto
<Property>
   <Name>calculateMoreAccurateFrameSize</Name>
   <Value>true</Value>
   <Type>Boolean</Type>
</Property>
<Property>
   <Name>calculateMoreAccurateFrameWindow</Name>
   <Value>200</Value>
   <Type>Integer</Type>
</Property>

```

Richard

---

<div class="post-metadata">

**Author:** ![HF\_Cheung](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@HF\_Cheung](https://community.wowza.com/u/HF_Cheung)\
**Post date:** [June 20, 2013, 9:22am UTC](https://community.wowza.com/t/set-duration-to-rtmp-mp3-streaming/40637/4 "2013-06-20T09:22:49Z")

</div>

> This might help. Add these Property settings to the Application.xml /MediaReader Properties container:
> 
> ```auto
> <Property>
> <Name>calculateMoreAccurateFrameSize</Name>
> <Value>true</Value>
> <Type>Boolean</Type>
> </Property>
> <Property>
> <Name>calculateMoreAccurateFrameWindow</Name>
> <Value>200</Value>
> <Type>Integer</Type>
> </Property>
> 
> ```
> 
> Richard

It doesn’t work.

Do you have any code that would modify the metadata of MP3?
