Developing A Streaming Server For Android

老子叫甜甜 提交于 2019-11-29 00:39:11

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!