3

我正在尝试从http://www.aftek.com/afteklab/aftek-RTMP-library.shtml实现库 以从 red5 服务器流式传输实时视频。

在服务器上,我使用的是 simpleBroadcaster,我想将它流式传输到 android 手机。

我的代码:

package com.cu.reader;

import java.nio.channels.FileChannel;
import java.util.Map;
import com.al.rtmp.client.RtmpClient;
import com.al.rtmp.client.RtmpStream;
import com.al.rtmp.client.RtmpStreamFactory;
import com.al.rtmp.client.data.MetaData;
import com.al.rtmp.client.data.RTMPData;
import com.al.rtmp.client.data.VideoCodec;
import com.al.rtmp.message.Metadata;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class StreamreaderActivity extends Activity implements RtmpClient {
     RtmpStream stream = null;
     Boolean connected = false;
 String server = "rtmp://216.224.181.197/oflaDemo/";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    stream = RtmpStreamFactory.getRtmpStream();
    stream.setClient(this);
    stream.connect(server);
}
@Override
public void streamCreated() {
    Log.i("stream","Connected!");       

    connected = true;
    stream.setPlayName("red5StreamDemo");
    stream.play();

}
@Override
public byte[] getWriteData(int length) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void invoke(String arg0, Object... arg1) {
    // TODO Auto-generated method stub
;   
}
@Override
public void onDataReceived(RTMPData rtmpData) {
    MetaData metaData = rtmpData.getMetaData();
    VideoCodec vc = metaData.getVideoCodec();
}
@Override
public void onError(Exception ex) {
    Log.e("ClientException", " Some exception occurred." + ex.getMessage());
    ex.printStackTrace();
}
@Override
public void onMetaDataReceived(Map map) {
    Log.i("code","METADATA:" + map);        

}
@Override
public void onResult(String method, Object... arg1) {
    Log.i("result","METADATA:" + method);       

}
@Override
public void onStatus(String code) {
    Log.i("code",code);     
}

}

我总是在 onStatus 函数中接收 NetStream.Play.StreamNotFound 。

谢谢

4

2 回答 2

1

您会收到 NetStream.Play.StreamNotFound 错误,因为 red5 应用程序上不存在此类流。

我做了快速 as3 测试来检查:

package {

import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

public class LearnWowzaClient extends Sprite {

    private var nc:NetConnection;
    private var video:Video = new Video();

    public function LearnWowzaClient() {

        nc = new NetConnection();
        nc.client = this;
        nc.addEventListener(NetStatusEvent.NET_STATUS, onNet);
        nc.connect("rtmp://216.224.181.197/oflaDemo/");
    }

    private function onNet(event:NetStatusEvent):void {
        trace(event);
        trace(event.info.code);
        switch (event.info.code) {
            case "NetConnection.Connect.Success":
                tryPlayStream();
                break;
        }
    }

    private function tryPlayStream():void {
        trace("playStream");
        var ns:NetStream = new NetStream(nc);
        ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
        ns.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
        ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);

        ns.play("red5StreamDemo");
        video.attachNetStream(ns);
    }

    public function onBWCheck(parameter:Object = null):void {
        trace("onBWCheck p=" + parameter);
    }

    public function onBWDone(parameter:Object = null):void {
        trace("onBWDone p=" + parameter);
    }

    private function onIOError(event:IOErrorEvent):void {
        trace("onIOError");
    }

    private function onAsyncError(event:AsyncErrorEvent):void {
        trace("onAsyncError");
    }

    private function onNetStatus(event:NetStatusEvent):void {
        trace("onNetStatus   ", event.info.code);
    }
}
}

我也收到 NetStream.Play.StreamNotFound 错误。你能显示red5应用程序代码吗?

于 2012-11-12T09:30:08.540 回答
0

流不存在,正确。但为什么?可能是一两个原因:您没有创建直播流和 2) 因为您使用了错误的范围。除非您手动进行不同的配置(这不太可能),否则请使用 /live 中的“实时”广播器范围。

因此,发布到 rtmp://216.224.181.197/live/red5StreamDemo 并订阅完全相同的 mrl,在此示例中为 rtmp://216.224.181.197/live/red5StreamDemo。注意:为此,您需要创建一个“实时”流并将其提供给您的 RED5 服务器。您可以使用 avconv(又名 ffmpeg)来创建 rtmp 提要。

于 2013-05-08T21:26:24.373 回答