Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

MediaException when starting two players

I try to start two players - one recording video, and one playing video.

 

If I start first the recording player and then try to start the playback player I get  "MediaException: Media cannot start while another media is active"

 

If I first start the playback player and then the recorder no exception occurs but once the recorder is started the playback player simply stops playing.

 

Does anyone have idea how to make them both run simultaneously?

 

This happens on bold 9000 with OS5.

----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: MediaException when starting two players

A little update on this:

 

When I first start the playback player and then at the moment I start the recorder player the playback stops and the PlayerListener notifies me with event=deviceUnavailable. Then if I stop the recorder I get deviceAvailable event.

Does that mean that there is no way to have two video players active?

 

I even tried starting the two players in separate applications but without success.

----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: MediaException when starting two players

Put your sample code here........!
=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: MediaException when starting two players

[ Edited ]

All right here it is:

First the recorder:

 

public class Recorder {

	private static Player player;
	public static ByteArrayOutputStream outStream = new ByteArrayOutputStream();
	private static RecordControl recordControl;
	private static VideoControl videoControl;

	public static void start(Screen m) {
		try {
			player = Manager
					.createPlayer("capture://video?encoding=video/3gpp&width=176&height=144&video_codec=H264&audio_codec=AMR");
			player.start();
			videoControl = (VideoControl) player.getControl("VideoControl");
			recordControl = (RecordControl) player.getControl("RecordControl");
			Field videoField = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,
					"net.rim.device.api.ui.Field");
			videoControl.setDisplaySize(50, 50);
			videoControl.setDisplayLocation(0, 0);
			videoControl.setVisible(true);
			synchronized (UiApplication.getEventLock()) {
				m.add(videoField);
			}
			outStream.reset();
			recordControl.setRecordStream(outStream);
			recordControl.startRecord();
		} catch (Throwable e) {
			show(e.toString());
		}
	}

	public static void stop() {
		recordControl.stopRecord();
		try {
			outStream.close();
		} catch (IOException e) {
		}
		player.close();
	}

	private static void show(final String msg) {
		UiApplication.getUiApplication().invokeLater(new Runnable() {
			public void run() {
				Dialog.alert(msg);
			}
		});
	}
}

 

 

And the playback player:

 

 

public class Receiver {
	private Player videoPlayer;
	private InputStream is;

	public synchronized void startStreamingPlayer(Screen vfm) throws Exception {
		try {
			is = this.getClass().getResourceAsStream("/tst.m4v");
			Debug.add("stream:" + is);
			videoPlayer = javax.microedition.media.Manager.createPlayer(is, "video/sbv");
			videoPlayer.realize();
			videoPlayer.addPlayerListener(new PlayerListener() {
				public void playerUpdate(final Player player, String event, Object eventData) {
					Debug.add(event + ";" + eventData);
				}
			});
			VideoControl _videoControl = (VideoControl) videoPlayer.getControl("VideoControl");
			Field vField = (Field) _videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,
					"net.rim.device.api.ui.Field");
			// _videoControl.setDisplaySize(50, 50);
			_videoControl.setVisible(true);
			_videoControl.setDisplayFullScreen(true);
			synchronized (UiApplication.getEventLock()) {
				vfm.add(vField);
			}
			VolumeControl vol = (VolumeControl) videoPlayer.getControl("VolumeControl");
			vol.setLevel(20);
			videoPlayer.start();
		} catch (Exception e) {
			Debug.add(this.getClass().getName() + "#startStreamingPlayer", e);
			throw e;
		}
	}

	public synchronized void stopRTPStreamReceiver() {
		try {
			is.close();
			videoPlayer.close();
		} catch (Exception e) {
		}
	}

}

 

 

 

 

 

----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: MediaException when starting two players

First you are not save the data into that specified file. Main problem is here:
public static void stop() 
{
	recordControl.stopRecord();
	try 
        {
		outStream.close();
	} 
        catch (IOException e) {}
	player.close();
}

 Write like this:

1. you are not close the player. Thats why you got exception.

private void stopVideoRecording() 
{
	try 
	{	
		videoControl.setVisible(false);
		recordControl.stopRecord();	
               recordControl.commit(); player.close(); 	
		fileConn=(FileConnection) Connector.open(PATH);
		if(!fileConn.exists())
			fileConn.create();
		OutputStream outStream=fileConn.openOutputStream();
		outStream.write(oStream.toByteArray());//ostream nothing but OutPutStream ostream;
                oStream.close();
		outStream.close();
		fileConn.close();			 
                UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
		UiApplication.getUiApplication().pushScreen(new PlayVideoScreen(PATH,encodingFormat));
	} //encodingFormat is: "capture://video?encoding=video/3gpp&width=176&height=144&video_codec=H264&audio_codec=AMR"
	catch (final Exception e) 
	{
	   UiApplication.getUiApplication().invokeAndWait(new Runnable() 
           {
               public void run() 
               {
                  Dialog.inform(e.toString());
               }
            });
	}	
}

 

 ==================================================================================

Feel free to click THUMB(like) symbol.

 

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: MediaException when starting two players

@alishaik786 I don't want to stop the players. They have to run simultaneously.
The idea is that one player will be recording and the other will play video at the same time.
----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Contributor
Posts: 49
Registered: ‎12-16-2010
My Device: 9700
My Carrier: Vodafone

Re: MediaException when starting two players

[ Edited ]

dx22 understand what you're attempting, sharing video in real-time right?

 

which OS are you targeting?

 

If that helps you I've  found similar issues when trying to start two audio players simultaneously :

The target was to have one for playing received audio from an RTP stream and other for sending the data recorded from microphone.

 

This "full-duplex" issue was happening on any OS < 5 , on some OS 5 devices but not on all (for eg on BB9700 it was working fine). And this issue looks to not happen on OS6 or greater. However on OS 6 still have a 2/3 seg buffer which is very annoying for real-time communications I don't know if you'll have same buffer issue for video but it is possible you find this problem also.

 

 

 

Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: MediaException when starting two players

@albertpv I am generally targetting >=4.6 but I will be satisfied with whatever works as a beginning.

I know about the audio players but there I did not have such problems but only the speech delay problems which took me quite some time to solve and get the audio delay under 1 sec.

However here with video players the situation is different - I just can't have both players running simultaneously.
----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Contributor
Posts: 49
Registered: ‎12-16-2010
My Device: 9700
My Carrier: Vodafone

Re: MediaException when starting two players

At least for me:

On earlier versions of OS5 i'm almost sure it was hard to enable two audio players at the same time  (one for recording, ne for playing)on the same UiApplication. There are some approaches doing an Application and a UiApplication for each player and communicating them on GlobalEventListener but II still never tried that because we're targetting OS6 at this moment.

 

On later versions it looks to work better, for eg a Bold with OS5 updated to last version didn't reproduce this problem.

 

If  you have available time you could try to see if that approach of two Apps , one Ui and one not, would work for you with video. If you surf the forum you will find some info about that.

 

We achieved to reduce delay on OS4.6 and OS5 but on OS6 never achieved to get less than 3 seg delay for audio.

Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: MediaException when starting two players

But we are talking about video here, its not the same, although the api is similar.
The query string for player creation is different and the behaviour is different.

I managed to get the audio players going and work stable but i have big issues with video players.
----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy