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
Contributor
roxburd
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified
Accepted Solution

Bug in media Manager/Player

I've been recording PCM audio and it's been recording and playing back.
I've been using recording using Manager.createPlayer("capture://audio?encoding=pcm") and setting record location to a file test.pcm
I've been playing back using Manager.createPlayer("file:///.../test.pcm")
All works nicely. I get playback with duration and mediaTime values.

Then I needed to move to the next stage and play not from a file but from an InputStream. "No bother" thinks I, I'll just use the other Manager.createPlayer method which takes an InputStream and a content type.
But it seems to be bust.

If I get an InputStream from the file and load it using Manager.createPlayer(is, "audio/pcm") I get "Could not load file: unsupported content type - audio/pcm". Not surprising (as I haven't seen it documented/reported as a supported content type) but worth a try.

If I call Manager.createPlayer(is, "audio/basic") with the same InputStream I get "Could not load file: Not a snd file" (but it is the same file as createPlayer(file) loaded without any problem).

If I call Manager.createPlayer(is, "audio/wav;codec=pcm") the player is created but calls to getDuration() return 0/TIME_UNKNOWN and when I call start() it fails to play the audio (method returns as if it's playing but it's not playing the audio and calls to getMediaTime() return 0/TIME_UNKNOWN).

If I call Manager.createPlayer(is, "audio/x-pcm") the player is created but calls to getDuration() return 0/TIME_UNKNOWN and when I call start() it plays the media just as if it were of zero length (starts and then immediately stops with no errors).

If I call Manager.createPlayer(is, "audio/x-pcm;codec=pcm") it does the same as for "audio/x-pcm".

I've also tried appending every combination of parameters to the content type (;rate=8000/16000, etc.); that doesn't help.

Out of curiosity, if I then record audio using "capture://audio" I get an AMR file recorded. If I load it with Manager.createPlayer(is, "audio/amr") it does play but the player has no idea how long the audio is or how long it's played for - all calls to getDuration() and getMediaTime() return TIME_UNKNOWN. I can't use AMR anyway.

It seems to me (assuming my coding and codec / content types and formats are correct) that there's a bug somewhere in the media playing components (Manager/Player). If the file has a .pcm suffix and you load the file directly it plays fine but if you pass it in as an InputStream there seems to be no combination of encoding/codec/content type which will play the media properly, especially for PCM.

Any help or advice much appreciated. Basically, I need to record in PCM and load it back up for playback via an InputStream.

Torch 8900 6.0.0.14

 

Thanks,

Dave

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Bug in media Manager/Player

Can you post a code sample here that shows the implementation you are using for playback?

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
Please use plain text.
Contributor
roxburd
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

Re: Bug in media Manager/Player

Hi Mark,

 

My (distilled, test) code is as follows. It is a very simple app which just records a second of audio and then plays it back. You should be able to drop it into a new Eclipse BB project and run:

 

package com.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.RecordControl;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

public class AudioTest extends UiApplication{

    public static void main(String[] args) {
        AudioTest app = new AudioTest();
        app.enterEventDispatcher();
    }
    
    public AudioTest() {
        AudioTestScreen screen = new AudioTestScreen();
        pushScreen(screen);
        RecordThread thread = new RecordThread(screen);
        thread.start();
    }
    
    static class AudioTestScreen extends MainScreen {
        AudioTestScreen() {
            setTitle("AudioTest");
        }
        
        public void add(String label) {
            synchronized(UiApplication.getEventLock()) {
                add(new RichTextField(label));
            }
        }
    }
    
    public class RecordThread extends Thread implements PlayerListener {
        AudioTestScreen screen;
        boolean done = false;
        
        public RecordThread(AudioTestScreen s) {
            screen = s;
        }
        
        public void run() {
            Player recordPlayer;
            try {
                screen.add("Initialising...");
                recordPlayer = Manager.createPlayer("capture://audio?encoding=pcm");
                recordPlayer.realize();
                RecordControl recordControl = (RecordControl)recordPlayer.getControl("RecordControl");
                recordControl.setRecordLocation("file:///store/home/user/test_audio.pcm");
                recordControl.startRecord();
                recordPlayer.start();
                screen.add("Recording...");
                try {Thread.sleep(1000);} catch (Exception e) {}
                recordControl.commit();
                recordPlayer.close();

                Player playPlayer = Manager.createPlayer("file:///store/home/user/test_audio.pcm"); // Method A
                
                //FileConnection fc = (FileConnection) Connector.open("file:///store/home/user/test_audio.pcm"); // Method B
                //InputStream is = fc.openInputStream(); // Method B
                //Player playPlayer = Manager.createPlayer(is, "audio/x-pcm"); // Method B
                
                playPlayer.addPlayerListener(this);
                playPlayer.start();
                long start = new Date().getTime();
                screen.add("Playing... (Reported duration: "+playPlayer.getDuration()/1000+"ms)");
                do {Thread.yield();} while (!done);
                long len = new Date().getTime() - start;
                playPlayer.close();
                screen.add("Done - Played for: "+len+"ms");
            } catch (IOException e1) {
                screen.add(e1.getMessage());
            } catch (MediaException e1) {
                screen.add(e1.getMessage());
            }
        }
        
        public void playerUpdate(Player source, String eventType, Object data) {
            if (eventType.equals("endOfMedia")) done = true;
        }
    }
}

 

----------------------------------------------------------------------------------------------

 

METHOD A - successful playback

 

Initialising...

Recording...

Playing... (Reported duration: 1183ms)

Done - Played for: 1583ms

-> Audio played back successfully

 

METHOD B - All attempts to playback audio fail

 

If I create the playPlayer with type = audio/x-pcm I get:

Reported duration 0ms

-> 'Plays' for 427ms but audio is silent - playback fails.

 

type = audio/pcm :

unsupported content type - audio/pcm

 

type = audio/basic

  or audio/basic;codec=pcm :

Error: Not a snd file (at createPlayer)

 

type = audio/mpeg;codec=pcm

  or type = audio/x-wav;codec=pcm :

Media unloaded while initializing

 

--

 

Clearly, the device is capable of playing back the audio recorded to the file - createPlayer(locator) used in Method A plays it just fine with correctly reported duration and the ability to fast-forward and rewind via setMediaTime(). But if you record to a file which does not end in .pcm (or remove it by renaming the file), even that method fails.

 

Furthermore, even if we can figure out what createPlayer(locator) does behind the scenes when it encounters a file ending with .pcm, I suspect that an InputStream may not support calls to setMediaTime() and it may be necessary to use a DataSource instead - another muddying of the waters.

 

Method B does work *partly* for AMR. I say partly as it doesn't report duration. Anyway, I can't use AMR.

 

This issue is a serious threat to our project so any help very much appreciated, Mark!

 

Cheers,

Dave

 

Torch 9800 v6.0.0.246

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Bug in media Manager/Player

[ Edited ]

Recording PCM audio from the BlackBerry gives you only the raw data, not wrapped in a container. To play it back, it must be in a container. When such a file is played back using the built in Media application or Player class, the BlackBerry accounts for this and creates its own header during playback. This does not appear to be occurring when the file is read in from an InputStream. 

Likely we have an issue that we're not doing this if the stream is provided to us. The simple answer is to add your own WAV header to the stream, then provide the data.

 

I have logged this issue in Issue Tracker here:  https://www.blackberry.com/jira/browse/JAVAAPI-1786

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
Please use plain text.
Contributor
roxburd
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

Re: Bug in media Manager/Player

Great, thanks Mark, I'll look into adding my own WAV header on there - doesn't look too complicated. Any advice on which settings (content type) to use to play it back once the header is in place? I'm guessing audio/x-pcm... or audio/basic... or audio/basic;codec=pcm...???

 

Also, any chance you could get me access to the issue tracker? I get a permission violation when I follow the link. It would be good to be able to track the issue.

 

Thanks,

Dave

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Bug in media Manager/Player

audio/pcm should work fine.

You can log into Issue Tracker using your Developer Zone account, which is the same one you use to access this forum.
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
Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Bug in media Manager/Player

I have also added some (unsupported, briefly tested) workaround code to the issue in Issue Tracker that can be used to write out the header.
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
Please use plain text.
Contributor
roxburd
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

Re: Bug in media Manager/Player

Hi Mark,

 

It turns out that I get a PERMISSION VIOLATION whether I'm logged in or not when I follow the link you gave. And I can't find the issue using the search function. It looks to me as if it's not released for public viewing.

 

Given that you've taken the trouble to produce workaround code, it would be great if I could get access.

 

> audio/pcm should work fine

 

On my 9800 that returns "unsupported content type - audio/pcm"

 

Thanks,

Dave

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Bug in media Manager/Player

Can you let me know whether or not you can log in here: http://us.blackberry.com/developers/
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
Please use plain text.
Contributor
roxburd
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

Re: Bug in media Manager/Player

Yes mate, I certainly can. Just to be doubly sure I logged out and logged back in again.

 

I can also log in to https://www.blackberry.com/jira/secure/Dashboard.jspa

 

When I navigate to FIND ISSUES and search on Java APIs the most recent is:

JAVAAPI-1780     OS 6.X prior to 6.0.0.526 on 9800 - Keyboard ...     RIM
msohm     jamescoleman     Critical     Waiting for Customer Waiting for Customer     UNRESOLVED     20/Apr/11     26/Apr/11
Bug

 

UPDATE on my PCM playback issue:

I can now whack a header on my PCM and playback!!

 

Many thanks Mark.

 

To playback I am using content type audio/x-wav

 

I have a loud blip on the end of the audio that I'm trying to iron out but I'm hoping that wont be a biggie.

 

It would be good to check out your workaround code - your code might remove the blip.

 

Thanks again,

Dave

 

PS I'll post my code when I've got rid of the blip.

Please use plain text.