2012-11-30 104 views
1

我想从我的电脑上的VLC流式传输到我的Android设备上运行Android 4.0.3,但不知何故,它只是不会工作,我搜索了互联网,它的错误意味着我正在使用错误的格式。不过,我已经有了正确的格式,不应该发生这种错误。所以我希望你们能帮我解决问题。MediaPlayer流式传输错误

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       : [email protected] 
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}' 
+0

在哪里存储您的视频? – znat

回答

1

从直播时互联网使用prepareAsync,而不是准备和调用onPrepared方法:

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

而且StreamPlayerListener类:

private class StreamPlayerListener implements OnPreparedListener { 

    @Override 
    public void onPrepared(MediaPlayer mp) { 
     player.start(); 
    } 
} 
+0

嗯,我试图不通过互联网,但以太网流。有什么区别吗?我的视频存储在PC上,我希望它能通过以太网传输到我的平板电脑 –