【问题标题】:J2ME RTSP Video Streams but no AudioJ2ME RTSP 视频流但没有音频
【发布时间】:2012-11-12 13:36:20
【问题描述】:

我关注了诺基亚关于使用 J2Me 创建视频播放器的 wiki。一般的代码是这样的

player = Manager.createPlayer("rtsp://v1.cache5.c.youtube.com/CjYLENy73wIaLQm8E_KpEOI9cxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYLm0hv_ig5HRTww=/0/0/0/video.3gp");               

                  //A player listener is needed so that we know, when the video has reached the END_OF_MEDIA position
            player.addPlayerListener(this);
            player.realize();
            player.prefetch();

          //The duration of the video
            duration = player.getDuration();

            //The video control instance is created and attached to this Canvas in Full SCreen mode
            vc = (VideoControl)player.getControl("VideoControl");

            voc = (VolumeControl)player.getControl("VolumeControl");
            voc.setLevel(100);
            voc.setMute(false);


            vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
            vc.setDisplaySize(240, 196);
            //vc.setDisplayFullScreen(true);

            vc.setVisible(true);





           // vc.setDisplayFullScreen(true);
            //next time the above operations will be skipped
            firstPlay = false;

          //A new thread handles the move of the cursor while the video progresses. 
            //The thread is distroyed when the video is stopped.
            thread = new Thread(this);
            thread.start();

目前我为诺基亚 Asha 311 开发。如果我​​只是通过浏览器打开 rtsp 地址,则会弹出原生视频播放器并将视频与音频一起流式传输,并且使用此代码,视频流式传输流畅但根本没有声音。

我做错了吗?感谢您的帮助

问候

【问题讨论】:

    标签: video java-me streaming nokia rtsp


    【解决方案1】:

    要播放 youtube 视频,您可以使用以下代码:

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.VideoControl;
    
    public class RTSPFullScreen extends MIDlet implements CommandListener, PlayerListener {
    
        private Display d;
        private Player p;
        private Canvas c;
        private Command exitCommand = new Command("Exit", Command.EXIT, 1);
        VideoControl vc;
    
        public RTSPFullScreen() {
    
            d = Display.getDisplay(this);
    
    
        }
    
        public void startApp() {
            c = new Canvas() {
    
                protected void paint(Graphics g) {
    
                    g.setColor(0, 0, 0);
                    g.fillRect(0, 0, getWidth(), getHeight());
    
    
                }
            };
    
            c.setFullScreenMode(true);
            c.addCommand(exitCommand);
            c.setCommandListener(this);
            d.setCurrent(c);
    
    
    
    
            try {
               p = Manager.createPlayer("rtsp://v1.cache5.c.youtube.com/CjYLENy73wIaLQm8E_KpEOI9cxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYLm0hv_ig5HRTww=/0/0/0/video.3gp");
    
    
                p.addPlayerListener(this);
                p.start();
    
                vc = (VideoControl) p.getControl("javax.microedition.media.control.VideoControl");
                vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, c);
    
    
    
            } catch (Exception e) {
                showAlert("startApp: " + e.toString());
            }
        }
    
        public void commandAction(Command c, Displayable s) {
            if (c == exitCommand) {
                destroyApp(false);
                notifyDestroyed();
            }
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean uc) {
            if (p != null) {
                p.close();
            }
        }
    
        public void playerUpdate(Player player, java.lang.String event, java.lang.Object eventData) {
            if (player.getState() == Player.STARTED) {
    
                try {
    
                    vc.setDisplayFullScreen(true);
                    vc.setVisible(true);
                } catch (Exception e) {
                    showAlert("playerUpdate: " + e.toString());
                }
            }
    
        }
    
        public void showAlert(String aAlertText) {
            Alert alert = new Alert("Alert", aAlertText, null, AlertType.ERROR);
            alert.setTimeout(10000);
            d.setCurrent(alert);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 2019-01-11
      相关资源
      最近更新 更多