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: 66
Registered: ‎08-21-2009
My Device: Not Specified

Getting "Media Exception: Media cannot start while another media is active"

Hi,

 

I am developing an application in which I am taking snap shots using inbuilt camera. I have used

javax.microedition.media.* APIs to launch and capture the snap. I have used same code available in sample application.

 

Also my application have Voice recording and play functionality. For this also we have used a

javax.microedition.media.* APIs.

 

I am recording the voice note and play the same note as well first time. Then I am taking a snap using inbuilt camera through my application.

 

My problem is: When I am trying to play Audio note after camera operations I am getting "Media Exception: Media cannot start while another media is active" exception and voice note does not play. Smiley Sad

 

We have stopped, deallocate, closed player after the use.

 

Observed behavior: When we close the camera externally then we are able to play voice note...   

 

Please help.... Waiting for any clue...

 

Regards,

Krmlkr.

BlackBerry Development Advisor
Posts: 15,209
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Getting "Media Exception: Media cannot start while another media is active"

What BlackBerry Smartphone model and BlackBerry device software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.

 

What do you mean by close the camera externally?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 66
Registered: ‎08-21-2009
My Device: Not Specified

Re: Getting "Media Exception: Media cannot start while another media is active"

I am using OS 5.0 device, BB 9330.

 

I mean: When I encountered this exception in my application, I have to open the native camera application and need close it manually. Then only I am able to play voice note from my application.

 

Regards,

Krmlkr.

BlackBerry Development Advisor
Posts: 15,209
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Getting "Media Exception: Media cannot start while another media is active"

What is the full, 4 digit version?  Can you post a code snippet that reproduces this?  Do you see the same behaviour when using the camerademo (and adding your voice note code)?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 66
Registered: ‎08-21-2009
My Device: Not Specified

Re: Getting "Media Exception: Media cannot start while another media is active"

Version: 5.0.0.782

 

We have following code to start Camera, take snap and close Camera:

 

// Create Player
player = Manager.createPlayer("capture://video");
player.realize();

_videoControl = (VideoControl) player.getControl("VideoControl");
if (_videoControl != null)  {
	_videoField = (Field) _videoControl.initDisplayMode(
	VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
	_videoControl.setDisplayFullScreen(true);			
	_videoControl.setVisible(true);
}
player.start();

// Take snap
byte[] raw = _videoControl.getSnapshot(null);
if(_videoField != null) {
	vfmManager.delete(_videoField);
	_videoField = null;
}
if(_videoControl != null) {
	_videoControl.setVisible(false);
	_videoControl = null;
}

// Close Camera
player.stop();
player.deallocate();
player.close();

 

Also we have used following code to start Audio player, recoed and close player:

 

// Create player
_player = Manager.createPlayer(new ByteArrayInputStream(data), "audio/x-wav");
_player.addPlayerListener(this);
_player.realize();
_player.prefetch();
_player.start();

// Stop player
_player.stop();
_player.deallocate();
_player.close();

 

Please check whether we are doing correct steps? Looking for any clue to come out of this problem....

 

Regards,

Krmlkr.

BlackBerry Development Advisor
Posts: 15,209
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Getting "Media Exception: Media cannot start while another media is active"

I haven't been able to reproduce this using the code you provided... assuming that the camera was closed before I attempt to play back the audio file.  If the camera viewfinder is displayed I do get the error you describe, which is expected.

 

Can you provide a larger sample (complete application)?  Are you seeing this in the simulator and real device, or just one or the other?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 66
Registered: ‎08-21-2009
My Device: Not Specified

Re: Getting "Media Exception: Media cannot start while another media is active"

We have observed this issue on few device like Storm (4.7) and Curve (5.0), not on all devices. This issue is not reproduced on simulator.

 

In addition, in event logs I found: "AVM, net.rim.device.apps.internal.camera.MMAPIViewfinderField@3f6f60f0".

 

Is it related to the view finder which is used in camera? If yes, then how we can close this view finder once we finish with Camera operations?

 

Regards,

Krmlkr

Retired
Retired
Posts: 150
Registered: ‎10-19-2010
My Device: Not Specified
My Carrier: Rogers

Re: Getting "Media Exception: Media cannot start while another media is active"

[ Edited ]

Are you starting the audio player in a different thread while you work with the camera player?  As Mark said this error occurs when you try to use both players at the same time.  If they are happening in different threads you may be creating a race condition where you have not deallocated() or closed() the camera player before you prefetch or start the audio player. 

 

To avoid this error your camera player must be at least deallocated() before the audio player is prefetched().  The player takes care of the viewfinder and its resources for you, as long as you maintain the order of operations I described you don't need to worry about the viewfinder field.

Developer
Posts: 66
Registered: ‎08-21-2009
My Device: Not Specified

Re: Getting "Media Exception: Media cannot start while another media is active"

Hi BVP,

 

There is no different threads. We are performing both operations in main thread only and at a time we are doing one operation either Camera or Audio playing. In both the cases we have used stop(); deallocate(); and close(); methods to close the respective player.

 

As I said earlier, when we open and close the native camera application, we are not getting such exception. After calling deallocate() and close() also Camera is not closing. Its strange  .

 

Regards,

Krmlkr.

Contributor
Posts: 10
Registered: ‎04-22-2013
My Device: Torch 9800
My Carrier: MTS

Re: Getting "Media Exception: Media cannot start while another media is active"

I faced with same issue on 7.1 OS. Is there any workaround to fix it?