开发者

Developing A Streaming Server For Android

开发者 https://www.devze.com 2023-02-22 21:24 出处:网络
I am trying to develop a Streaming AV Media Server for use with an Android handset as the client. This instantly puts a constraint on me to develop a server that uses RTSP. I am versed in Java program

I am trying to develop a Streaming AV Media Server for use with an Android handset as the client. This instantly puts a constraint on me to develop a server that uses RTSP. I am versed in Java programming and have found that Netty (Java NIO) can be used to fill in the otherwise massive gap in the Java Media Framework for this protocol. I have played around with it and have had no real success. I know about live555 but I’m on a tight schedule and don't really want to start messing around with C++ as I know very little on the subject. I have been stuck on this problem for many weeks and have nothing really to show for it. Streaming to android开发者_如何学JAVA must be possible as there are numerous proprietary apps on the Android market. Could someone who has experience and knowledge on this subject please let me know if there is a simple way to implement an RTSP AV media server that just streams .mp4 or .3gp and .mp3 for use with android without using the live555 libraries. If not I will just have to quickly get up to speed on C++. Thank you in advance.


OK, simple as this to stream using HTTP.

I created a virtual folder called 'Music' with IIS on WinXP and pointed it at a folder containing mp3 files. This is the complete Activity needed to stream a file (name hard-coded).

BTW, it's called SimpleNetRadio as I originally started playing around with Shoutcast streams.

package com.mycompany.SimpleNetRadio;

import android.app.Activity;
import android.media.AsyncPlayer;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;

public class SimpleNetRadio extends Activity
{
    private AsyncPlayer ap = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    protected void onStart() {
        super.onStart();
        ap = (AsyncPlayer) getLastNonConfigurationInstance();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (ap != null)
            ap.stop();
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (ap == null) {
            ap = new AsyncPlayer("Simple Player");
            ap.play(this, Uri.parse("http://192.168.1.1/Music/02%20-%20Don't%20Stop%20Believin'.mp3"), true, AudioManager.STREAM_MUSIC);
        }
    }

    @Override
    public Object onRetainNonConfigurationInstance() {
        return ap;
    }
}

You should also be able to do this with MediaPlayer with a bit more code - it would handle error conditions better and wouldn't require much more work.


Developing a RTSP streaming server with Netty is fairly straight forward task and doesn't take much of time. I myself have written it and it worked like a charm. You could look at the sample implementations of some other servers using Netty framework to get started.


I'm not sure what your specific needs are, but for static files you might try combining Amazon S3 and CloudFront, which I believe supports RTSP.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号