1

我正在尝试从我的 PC 上的 VLC 流式传输到在 Android 4.0.3 上运行的 Android 设备,但不知何故它无法正常工作,我搜索了互联网,我的错误意味着我使用了错误的格式。但是我已经得到了正确的格式,这个错误不应该发生。所以我希望你们能帮助我解决问题所在。

MediaPlayer player;
SurfaceHolder holder;
SurfaceView surfaceView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    surfaceView = (SurfaceView) findViewById(R.id.rtspStream);
    holder = surfaceView.getHolder();
    holder.addCallback(this);
    player = new MediaPlayer();
    player.setOnErrorListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
    try
    {
        if(holder.equals(holder))
        {
            player.setDataSource(this,Uri.parse("rtsp://192.168.0.3:8080/test.sdp"));
            player.setDisplay(holder);          
            player.prepare();
            player.start();
        }
    }
    catch(Exception e){
        Log.e("MEDIA", e.toString());
    }
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub  
}
@Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
    if(arg0.equals(player)){
        if(arg1 == MediaPlayer.MEDIA_ERROR_UNKNOWN){
            Log.d("onError","extra "+arg2);
        }

    }
    return false;
}

这是我的测试课。我的 Logcat 看起来像这样

01-01 03:02:05.571: D/libEGL(2554): loaded /system/lib/egl/libGLES_android.so
01-01 03:02:05.571: D/libEGL(2554): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
01-01 03:02:05.587: D/libEGL(2554): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
01-01 03:02:05.595: D/libEGL(2554): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
01-01 03:02:05.720: D/OpenGLRenderer(2554): Enabling debug mode 0
01-01 03:02:05.727: D/MediaPlayer(2554): Couldn't open file on client side, trying server side
01-01 03:02:08.837: E/MediaPlayer(2554): error (1, -2147483648)
01-01 03:02:08.837: E/MediaPlayer(2554): Error (1,-2147483648)
01-01 03:02:08.837: D/onError(2554): extra -2147483648

我的测试视频的信息是这样的:

General
Complete name                            : testing.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom
File size                                : 84.0 MiB
Duration                                 : 2mn 1s
Overall bit rate mode                    : Variable
Overall bit rate                         : 5 776 Kbps
Writing application                      : Lavf53.21.0

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Baseline@L4.0
Format settings, CABAC                   : No
Format settings, ReFrames                : 3 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 2mn 1s
Bit rate                                 : 5 740 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 29.970 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.092
Stream size                              : 83.4 MiB (99%)
Writing library                          : x264 core 120 r2171 01f7a33
Encoding settings                        : cabac=0 / ref=3 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.25 / aq=1:1.00
Language                                 : English

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 2mn 1s
Bit rate mode                            : Variable
Bit rate                                 : 33.3 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 16.0 KHz
Compression mode                         : Lossy
Stream size                              : 493 KiB (1%)
Language                                 : English

我在终端中运行 VLC:

vlc -vvv testing.mp4 --sout '#rtp{dst=192.168.0.7,port=1234,sdp=rtsp://192.168.0.3:8080/test.sdp}'
4

1 回答 1

1

从互联网流式传输时,使用 prepareAsync 而不是 prepare 并从 onPrepared 方法调用 start:

player.setOnPreparedListener( new StreamPlayerListener() );         
player.prepareAsync();

和 StreamPlayerListener 类:

private class StreamPlayerListener implements OnPreparedListener {

    @Override
    public void onPrepared(MediaPlayer mp) {
        player.start();
    }
}
于 2012-11-30T15:03:54.693 回答