# IMediaWriterActionNotify: file write listener

**URL:** https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91
**Category:** Wowza Developer Dojo
**Tags:** wowza-streaming-server-java-api
**Created:** [February 15, 2010, 1:17pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91 "2010-02-15T13:17:41Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/system/32/447_2.png) [@system](https://community.wowza.com/u/system)
#### Post date: [February 15, 2010, 1:17pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/1 "2010-02-15T13:17:41Z")

</div>

[https://www.wowza.com/docs/how-to-use-imediawriteractionnotify-to-programmatically-move-and-rename-recordings-of-live-streams](https://www.wowza.com/docs/how-to-use-imediawriteractionnotify-to-programmatically-move-and-rename-recordings-of-live-streams)

---

<div class="post-metadata">

### Author: ![lechie\_chao](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@lechie\_chao](https://community.wowza.com/u/lechie_chao)
#### Post date: [September 7, 2010, 4:04am UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/2 "2010-09-07T04:04:15Z")

</div>

hi charlie,

It’s a big help for me to move files automatically after a file has been recorded to disk.But I am failed to achieve this goal.

I downloaded the wowza IDE,and created a project and class files.

this is my java code:(to rename the file according to system date)

```auto
package com.wowza.wms.plugin.extend.module;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import com.wowza.wms.application.*;
import com.wowza.wms.module.*;
import com.wowza.wms.stream.*;
public class ModuleMediaWriterFileMover extends ModuleBase
{
	class WriteListener implements IMediaWriterActionNotify
	{
		public void onFLVAddMetadata(IMediaStream stream, Map<String, Object> extraMetadata)
		{
			getLogger().info("ModuleWriteListener.onFLVAddMetadata["+stream.getContextStr()+"]");
		}
		public void onWriteComplete(IMediaStream stream, File file)
		{
			//getLogger().info("run here");
			
			String fileDir = file.getAbsolutePath();
			
			String filename = file.getName();
			
			File f_old = file;
			File f_new = null;
			String str = null;
			Date d = new Date();
			SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
			str = date.format(d);
			str = str.replace("-","");
			
			f_old = new File(fileDir,filename);
			f_new = new File(fileDir,"CBSJ_"+str+"_"+filename);
				
			f_old.renameTo(f_new);
			
			getLogger().info("ModuleWriteListener.onWriteComplete["+stream.getContextStr()+"]: "+file);
		}
		
	}
	
	public void onAppStart(IApplicationInstance appInstance)
	{
		//getLogger().info("run here");
		appInstance.addMediaWriterListener(new WriteListener());
		//getLogger().info("run here");
	}
}

```

Then copy the jar file to the wowza lib folder ,And I added the module to the application.xml file:

```auto
<Module>
<Name>ModuleMediaWriterFileMover</Name>
<Description>ModuleMediaWriterFileMover</Description>
<Class>ccom.wowza.wms.plugin.extend.module.ModuleMediaWriterFileMover</Class>
</Module>

```

But it seems do not work at all.could you have a look? is there any thing wrong in my config procedure?

---

<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: [September 7, 2010, 12:11pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/3 "2010-09-07T12:11:46Z")

</div>

Is the built-in Module also in the Application.xml?

If you uncomment the logger statement, do you see it in the logs?:

```auto
//getLogger().info("run here");

```

If yes, have you stepped through the following lines, or added logger statements to debug?

You can add try/catch block and put a logger statement in the catch.

Richard

---

<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: [September 7, 2010, 1:15pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/4 "2010-09-07T13:15:04Z")

</div>

Great! Thanks for the update.

Richard

---

<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: [November 8, 2010, 1:13pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/5 "2010-11-08T13:13:36Z")

</div>

You can’t have to Modules with the same name. The built-in one is:

```auto
<Module>
	<Name>ModuleMediaWriterFileMover</Name>
	<Description>ModuleMediaWriterFileMover</Description>
	<Class>com.wowza.wms.module.ModuleMediaWriterFileMover</Class>
</Module>

```

This is a built-in Module, you just need to add this to the Application.xml Modules list. Make sure it is last, at the bottom of the list.

If you have built the source code in that Article, and want to use your custom version, take out the built-in version.

Richard

---

<div class="post-metadata">

### Author: ![Andrew\_Kennedy](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Andrew\_Kennedy](https://community.wowza.com/u/Andrew_Kennedy)
#### Post date: [November 8, 2010, 2:43am UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/6 "2010-11-08T02:43:07Z")

</div>

I think you only need one entry for the application.xml of

ModuleMediaWriterFileMover

ModuleMediaWriterFileMover

com.wowza.wms.plugin.extend.module.ModuleMediaWriterFileMover

As suggested in the first post ?

Shamrock

---

<div class="post-metadata">

### Author: ![Andrew\_Kennedy](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Andrew\_Kennedy](https://community.wowza.com/u/Andrew_Kennedy)
#### Post date: [November 8, 2010, 3:53am UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/7 "2010-11-08T03:53:39Z")

</div>

the only thing I can think of is that you have two .jar files conflicting with the same class names.

looking through the code you do need only one entry in Application.xml, so seems to suggest something gone wrong with compiling it in the IDE or not added to the lib directory of the Wowza install.

Shamrock

---

<div class="post-metadata">

### Author: ![Sean\_conry](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sean\_conry](https://community.wowza.com/u/Sean_conry)
#### Post date: [October 7, 2011, 8:46am UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/8 "2011-10-07T08:46:02Z")

</div>

> Hi,thank you Richard for your reply.with your help I solve the problem,thank you very much again.

Hi lechi,

could you share your final codes with us.

thanks

---

<div class="post-metadata">

### Author: ![lechie\_chao](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@lechie\_chao](https://community.wowza.com/u/lechie_chao)
#### Post date: [September 7, 2010, 5:11am UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/9 "2010-09-07T05:11:22Z")

</div>

> Is the built-in Module also in the Application.xml?
> 
> If you uncomment the logger statement, do you see it in the logs?:
> 
> ```auto
> //getLogger().info("run here");
> 
> ```
> 
> If yes, have you stepped through the following lines, or added logger statements to debug?
> 
> You can add try/catch block and put a logger statement in the catch.
> 
> Richard

Hi,thank you Richard for your reply.with your help I solve the problem,thank you very much again.

---

<div class="post-metadata">

### Author: ![Apostol\_Raykov](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@Apostol\_Raykov](https://community.wowza.com/u/Apostol_Raykov)
#### Post date: [November 8, 2010, 12:02pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/10 "2010-11-08T12:02:18Z")

</div>

Hello, I tried to make this work, created the project and a class file. Pasted lechie’s code and added the following to Application.xml

```auto
<Module>
        <Name>ModuleMediaWriterFileMover</Name>
        <Description>ModuleMediaWriterFileMover</Description>
        <Class>com.wowza.wms.module.ModuleMediaWriterFileMover</Class>
</Module>
<Module>
        <Name>ModuleMediaWriterFileMover</Name>
        <Description>ModuleMediaWriterFileMover</Description>
        <Class>com.wowza.wms.plugin.extend.module.ModuleMediaWriterFileMover</Class>
</Module>

```

and

```auto
<Property>
        <Name>fileMoverDestinationPath</Name>
        <Value>${com.wowza.wms.context.VHostConfigHome}/content/acopy</Value>
</Property>
<Property>
        <Name>fileMoverDeleteOriginal</Name>
        <Value>false</Value>
        <Type>Boolean</Type>
</Property>
<Property>
        <Name>fileMoverVersionFile</Name>
        <Value>true</Value>
        <Type>Boolean</Type>
</Property>

```

The file is moved to destination, but without any date change in the name. Only versioning.

Can you help me? This is my first try to work with java and wowza IDE. I’m sure I messed something.

---

<div class="post-metadata">

### Author: ![Apostol\_Raykov](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@Apostol\_Raykov](https://community.wowza.com/u/Apostol_Raykov)
#### Post date: [November 8, 2010, 12:53pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/11 "2010-11-08T12:53:48Z")

</div>

Nothing happens only with one entry. The file stays in the current dir without any changes.

---

<div class="post-metadata">

### Author: ![Apostol\_Raykov](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@Apostol\_Raykov](https://community.wowza.com/u/Apostol_Raykov)
#### Post date: [November 8, 2010, 3:57pm UTC](https://community.wowza.com/t/imediawriteractionnotify-file-write-listener/91/12 "2010-11-08T15:57:02Z")

</div>

Thanks! I will keep trying. The custom code doesn’t work for me and I am not so good to debug it as lechie did.
