Cling Support for streaming from Android

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Cling Support for streaming from Android

DRichardson
I have a functional android program that allows me to stream in video from a url. If all I want to do is add a button next to the play and pause buttons that would allow the android device to connect to another device, what exactly would I need to do to get that set up? I don't have much experience with this technology, and any assistance would be much appreciated!

I've already imported the packages and made the permission adjustments in the xml file.

For reference, I have posted the video player fragment below.

public class VideoPlayerFragment extends Fragment {


    MediaPlayer mediaPlayer;
    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    boolean pausing = false;

    int currentMovie;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        View layout = inflater.inflate(R.layout.video_player, container, false);

        Button buttonPlayVideo = (Button)layout.findViewById(R.id.playvideoplayer);
        Button buttonPauseVideo = (Button)layout.findViewById(R.id.pausevideoplayer);

        getActivity().getWindow().setFormat(PixelFormat.UNKNOWN);
        surfaceView = (SurfaceView)layout.findViewById(R.id.surfaceview);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.setFixedSize(300, 400);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mediaPlayer = new MediaPlayer();

        if(Model.inst().getCurrentMovie() != 0){

            currentMovie = Model.inst().getCurrentMovie();
            buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

                @Override
                public void onClick(View arg0) {
                    pausing = false;

                    if(mediaPlayer.isPlaying()){
                        mediaPlayer.reset();
                    }

                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mediaPlayer.setDisplay(surfaceHolder);

                    String id = Integer.toString(currentMovie);

                    String building = Model.inst().getUrl();
                    String apiReq = "/api/1.0/videoPlayer?player_movieID=";
                    String sesh = "&session_key=";
                    String seshkey = Model.inst().getSession_id();

                    String url = building + apiReq + id + sesh + seshkey;

                    try {
                        mediaPlayer.setDataSource(url);
                        mediaPlayer.prepare();
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }


                    mediaPlayer.start();

                }});

            buttonPauseVideo.setOnClickListener(new Button.OnClickListener(){

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    if(pausing){
                        pausing = false;
                        mediaPlayer.start();
                    }
                    else{
                        pausing = true;
                        mediaPlayer.pause();
                    }
                }});

        }

        return layout;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Model.inst().setCurrentMovie(0);
        mediaPlayer.release();
    }
}