当前位置:编程学习 > wap >>

黑莓上播放sourcestream,使用pcm格式为什么没有声音

想使用sourcestream来播放:
在创建player的时候使用了“audio/x-pcm”,“audio/pcm”在运行的时候会出异常,所以才使用了x-。

try
        {
            player = Manager.createPlayer(new DataSource(null)
            {
                SourceStream[] mStream = {mInput};

                public void connect() throws IOException
                {
                    Log.d("read", "createPlayer: connect data source");
                    // ssLogger.info("connect data source");
                }

                public void disconnect()
                {
                    Log.d("read", "createPlayer: disconnect data source");
                    // sLogger.info("disconnect data source");
                }

                public String getContentType()
                {
                    Log.d("read", "createPlayer: getContentType");
                    return contentType;
                    // return "audio/basic;codec=pcm";
                }

                public SourceStream[] getStreams()
                {
                    Log.d("read", "createPlayer: getStreams");
                    return mStream;
                }

                public void start() throws IOException
                {
                    Log.d("read", "createPlayer: start data source");
                    // sLogger.info("start data source");
                }

                public void stop() throws IOException
                {
                    Log.d("read", "createPlayer: stop data source");
                    // sLogger.info("start data source");
                }

                public Control getControl(String controlType)
                {
                    Log.d("read", "createPlayer: getControl");
                    return null;
                }

                public Control[] getControls()
                {
                    Log.d("read", "createPlayer: getControls");
                    return null;
                }
            });
            player.addPlayerListener(this);
            player.realize();
            AudioPathControl lPathCtr = (AudioPathControl) player
                .getControl("net.rim.device.api.media.control.AudioPathControl");
            lPathCtr.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSET);
            player.prefetch();
            player.start();
        }
        catch (MediaException e)
        {
            Log.d("read", "MediaException" + e.toString());
            e.printStackTrace();
        }
        catch (IOException e)
        {
            Log.d("read", "IOException" + e.toString());
            e.printStackTrace();
        }
        Log.d("read", "player ready");
    }


SourceStream是这么定义 的

private SourceStream mInput = new SourceStream()
    {
        long mDebugSeq = 0;

        private int mAvailableSize = 0;

        private int mPacketSize;

        private ContentDescriptor mContentDescriptor = new ContentDescriptor(
            "audio/pcm");

        public int read(byte[] b, int offset, int length) throws IOException
        {
            //往b中复制数据

        }

        public ContentDescriptor getContentDescriptor()
        {
            Log.d("read", "getContentDescriptor");
            return mContentDescriptor;
        }

        public long getContentLength()
        {
            Log.d("read", "getContentLength");
            return playByte.length;
        }

        public int getSeekType()
        {
            Log.d("read", "getSeekType");
            return SourceStream.NOT_SEEKABLE;
        }

        public int getTransferSize()
        {
            Log.d("read", "SourceStream getTransferSize()");
            return 58000;
        }

        public long seek(long where) throws IOException
        {
            Log.d("read", "seek");
            return where;
        }

        public long tell()
        {
            Log.d("read", "seek");
            return startTime == 0 ? 0
                : (System.currentTimeMillis() - startTime);
        }

        public Control getControl(String controlType)
        {
            Log.d("read", "getControl");
            return null;
        }

        public Control[] getControls()
        {
            Log.d("read", "getControls");
            return null;
        }
    };


在运行的时候,没声音。请教如何解决。
这里的playByte是byte[],是我之前录下来的pcm格式的声音,已经测试过直接将playByte播放出来是可以有声音的。
--------------------编程问答-------------------- 楼猪,研究出来没,俺也在搞这个 --------------------编程问答--------------------
补充:移动开发 ,  BlackBerry
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,