package com.example.TreballFiGrau;



import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.VideoView;

import com.squareup.picasso.Picasso;

public class Video extends Fragment {

	ViewGroup rootView;
	String url = "http://tfg-sharenews.rhcloud.com/media/";
	String path;
	MediaPlayer mediaPlayer;
    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    boolean pausing = false;
    VideoView mVideoView;
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
    	rootView = (ViewGroup) inflater.inflate(R.layout.video, container, false);
    	
    	Log.d("aki", "dintre fragment foto");
    	if(PontFotoVideoFragment.urlPath.size()!=0){
    		path =PontFotoVideoFragment.urlPath.get(0);
    		PontFotoVideoFragment.urlPath.remove(0);
    		Log.d("aki", "despres remove");
    	}
    	
    	Log.d("aki", path);
    	
    	
    	mVideoView = (VideoView) rootView.findViewById(R.id.videoviewllegir);
    	
    	
        Uri uri = Uri.parse(url+path);
        mVideoView.setVideoURI(uri);
        mVideoView.requestFocus();
        MediaController media =  new MediaController(rootView.getContext());
        media.setEnabled(true);
        media.show(); 
        
        mVideoView.setMediaController(media);
        mVideoView.setEnabled(true);
        mVideoView.requestFocus();

        //mVideoView.start();
    	Log.d("aki", "despres fragment foto");
        return rootView;
    }
    public void mostrarFoto(String path){
    	
    	Log.d("aki", "dintre funcio mostrarFoto");
    	String url = "http://tfg-sharenews.rhcloud.com/media/";
    	Log.d("aki", url+path);
    	//Picasso.with(rootView.getContext()).load(url+path).into(im);
    	//Picasso.with(rootView.getContext()).load("http://tfg-sharenews.rhcloud.com/media/img/2014/05/30/grey_knight_term_150_129.gif/").into(im);
    	Log.d("aki", "despres picaso");
    	
    }
}
