J2ME RTSP视频流,但无音频 [英] J2ME RTSP Video Streams but no Audio

查看:104
本文介绍了J2ME RTSP视频流,但无音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直关注诺基亚的Wiki,了解如何使用J2Me创建视频播放器.通常代码是这样的

I've followed Nokia's wiki about creating the video player with J2Me. Generally the code is like these

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();

当前,我是为Nokia Asha 311开发的.如果我只是通过浏览器打开rtsp地址,则本机视频播放器将弹出并使用音频流传输视频,并使用此代码可以流畅地播放视频,但根本没有声音.

Currently I developed for Nokia Asha 311. If I just open the rtsp address via browser the native video player will pop up and streams the video with the audio, and with this code the Video streams smoothly but no sound at all.

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

Did i do something wrong? Thanks for your help

致谢

推荐答案

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

To stream an play youtube videos you can use the below Code:

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);
    }
}

这篇关于J2ME RTSP视频流,但无音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆