Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android视频流上传到php服务器?_Android_Android Webview_Android Video Player - Fatal编程技术网

Android视频流上传到php服务器?

Android视频流上传到php服务器?,android,android-webview,android-video-player,Android,Android Webview,Android Video Player,嗨 有人建议将视频数据发布到服务器上的一些示例和想法吗?我想稍后直接从服务器上以流式视频的形式播放视频。有人建议我如何将流式视频上传到php服务器并从服务器上以流式视频的形式播放。muniir@msn.com写道: public class SocialHTTPPost { public static byte[] getCapturedImageStream(Context ctx, Intent data) { String fileName = ((Ma

有人建议将视频数据发布到服务器上的一些示例和想法吗?我想稍后直接从服务器上以流式视频的形式播放视频。有人建议我如何将流式视频上传到php服务器并从服务器上以流式视频的形式播放。

muniir@msn.com写道:

public class SocialHTTPPost 
{ 
    public static byte[] getCapturedImageStream(Context ctx, Intent data)
    {
        String fileName = ((MainActivity) ctx).mCaptureImageHMap.get("name").toString();
        int mid= fileName.lastIndexOf(".");
        String ext=fileName.substring(mid+1,fileName.length());

        Bundle b = data.getExtras();
        Bitmap bmp = (Bitmap) b.get("data");
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if(ext.equalsIgnoreCase("png"))
            bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        else if(ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg"))
            bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] bytes = stream.toByteArray();        
        return bytes;
    }

    public static void postImage(Context ctx, byte[] ba)
    {       
        String sid = ((MainActivity) ctx).mCaptureImageHMap.get("sid").toString();

        String ba1=Base64.encode(ba);
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("image",ba1));

        for (Iterator iter = ((MainActivity) ctx).mCaptureImageHMap.entrySet().iterator(); iter.hasNext();) 
        {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = (String)entry.getKey();
            String value = (String)entry.getValue();
            nameValuePairs.add(new BasicNameValuePair(key, value));
        }

        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(Config.MEDIA_IMAGE_PATH + "?AddFile=AddFile&SessionId=" + sid);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            //is = entity.getContent();
        }
        catch(Exception e)
        {
            CommonFunctions.writeLOG(ctx.getClass().toString(), e.toString());
            CommonFunctions.showToast(ctx, "Unable to post captured image file: " + e.toString());
        }       
    }

    public static byte[] getCapturedVideoStream(Context ctx, Intent data)
    {       
        try 
        {
            AssetFileDescriptor videoAsset = ctx.getContentResolver().openAssetFileDescriptor(data.getData(), "r");
            FileInputStream fis = videoAsset.createInputStream();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            try 
            {
                for (int readNum; (readNum = fis.read(buf)) != -1;)                
                    bos.write(buf, 0, readNum);
            } 
            catch (IOException e) 
            {
                CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(), e.toString());
            }
            byte[] bytes = bos.toByteArray();
            return bytes;
        } 
        catch (IOException e) 
        {
            CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(), e.toString());
            return null;
        }       
    }

    public static void postVideo(Context ctx, byte[] ba)
    {       
        String sid = ((MainActivity) ctx).mCaptureVideoHMap.get("sid").toString();

        String ba1=Base64.encode(ba);
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("video",ba1));

        for (Iterator iter = ((MainActivity) ctx).mCaptureVideoHMap.entrySet().iterator(); iter.hasNext();) 
        {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = (String)entry.getKey();
            String value = (String)entry.getValue();
            nameValuePairs.add(new BasicNameValuePair(key, value));
        }

        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(Config.MEDIA_VIDEO_PATH + "?AddFile=AddFile&SessionId=" + sid);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            //HttpEntity entity = response.getEntity();
        }
        catch(Exception e)
        {
            CommonFunctions.writeLOG(ctx.getClass().toString(), e.toString());
            CommonFunctions.showToast(ctx, "Unable to post captured video file: "  + e.toString());
        }       
    }

    //  //////////////////////////////////////////  SAMPLE TEST START FOR READING WRITING IMAGES AND VIDEO BINARY

    public static boolean writeCaptureVideo(Context ctx, Intent data)
    {       
        String fileName = ((MainActivity) ctx).mCaptureImageHMap.get("name").toString();
        String sid = ((MainActivity) ctx).mCaptureImageHMap.get("sid").toString();
        String path = ""; //((MainActivity) ctx).mMediaPath;

        try 
        {
            AssetFileDescriptor videoAsset = ctx.getContentResolver().openAssetFileDescriptor(data.getData(), "r");
            FileInputStream fis = videoAsset.createInputStream();           
            File tmpFile = new File(path, fileName); 
            FileOutputStream fos = new FileOutputStream(tmpFile);
            byte[] buf = new byte[1024];
            int len;
            while ((len = fis.read(buf)) > 0) 
            {
                fos.write(buf, 0, len);
            }       
            fis.close();
            fos.close();
            return true;
        } 
        catch (IOException e) 
        {
            CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(), e.toString());
            return false;
        }       
    }

    public static boolean writeCaptureImage(Context ctx, Intent data)
    {
        String fileName = ((MainActivity) ctx).mCaptureImageHMap.get("name").toString();
        String path = ""; //((MainActivity) ctx).mMediaPath;

        int mid= fileName.lastIndexOf(".");
        String ext=fileName.substring(mid+1,fileName.length());
        File file = new File(path, fileName);
        Uri outputFileUri = Uri.fromFile( file );
        Bundle b = data.getExtras();
        Bitmap bm = (Bitmap) b.get("data");

        try 
        {               
            if(ext.equalsIgnoreCase("png"))
                bm.compress(CompressFormat.PNG, 100, new FileOutputStream(file));
            else if(ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg"))
                bm.compress(CompressFormat.JPEG, 100, new FileOutputStream(file));
            try {
                Runtime.getRuntime().exec("chmod 777 " + path + "/" + fileName);
            } catch (IOException e1){}

            return true;
        } 
        catch (FileNotFoundException e) 
        {
            CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(), e.toString());
            return false;
        }       
    }

    public static void postImage2(Context ctx)
    {
        //help site:    http://blog.sptechnolab.com/2011/03/09/android/android-upload-image-to-server/
        String fileName = ((MainActivity) ctx).mCaptureImageHMap.get("name").toString();
        String sid = ((MainActivity) ctx).mCaptureImageHMap.get("sid").toString();
        String path = ""; //((MainActivity) ctx).mMediaPath;

        int mid= fileName.lastIndexOf(".");             
        String ext=fileName.substring(mid+1,fileName.length());

        //InputStream is;
        Bitmap bitmapOrg = BitmapFactory.decodeFile(path + "/" + fileName);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();

        if(ext.equalsIgnoreCase("png"))
            bitmapOrg.compress(Bitmap.CompressFormat.PNG, 100, bao);
        else if(ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg"))
            bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 100, bao);

        byte [] ba = bao.toByteArray();
        String ba1=Base64.encode(ba);
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("image",ba1));

        for (Iterator iter = ((MainActivity) ctx).mCaptureImageHMap.entrySet().iterator(); iter.hasNext();) 
        {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = (String)entry.getKey();
            String value = (String)entry.getValue();
            nameValuePairs.add(new BasicNameValuePair(key, value));
        }       

        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(Config.MEDIA_IMAGE_PATH + "?AddFile=AddFile&SessionId=" + sid );
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            //is = entity.getContent();
        }
        catch(Exception e)
        {
            CommonFunctions.writeLOG(ctx.getClass().toString(), e.toString());
            CommonFunctions.showToast(ctx, "Unable to post captured image file: " + fileName);
        }       
    }

    //  //////////////////////////////////////////  SAMPLE TEST END
}
公共类社交HttpPost
{ 
公共静态字节[]getCapturedImageStream(上下文ctx,意图数据)
{
字符串文件名=((MainActivity)ctx.mcaptureMageHMap.get(“name”).toString();
int mid=fileName.lastIndexOf(“.”);
字符串ext=fileName.substring(mid+1,fileName.length());
Bundle b=data.getExtras();
位图bmp=(位图)b.get(“数据”);
ByteArrayOutputStream=新建ByteArrayOutputStream();
if(ext.equalsIgnoreCase(“png”))
bmp.compress(Bitmap.CompressFormat.PNG,100,流);
else if(ext.equalsIgnoreCase(“jpg”)| | ext.equalsIgnoreCase(“jpeg”))
bmp.compress(Bitmap.CompressFormat.JPEG,100,流);
byte[]bytes=stream.toByteArray();
返回字节;
}
公共静态void postImage(上下文ctx,字节[]ba)
{       
字符串sid=((MainActivity)ctx.mcaptureMageHMap.get(“sid”).toString();
字符串ba1=Base64.encode(ba);
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“图像”,ba1));
for(迭代器iter=((MainActivity)ctx.mcaptureMageHMap.entrySet().Iterator();iter.hasNext();)
{
Map.Entry=(Map.Entry)iter.next();
String key=(String)entry.getKey();
String value=(String)entry.getValue();
添加(新的BasicNameValuePair(键,值));
}
尝试
{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost-HttpPost=newhttppost(Config.MEDIA\u IMAGE\u PATH+”?AddFile=AddFile&SessionId=“+sid”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
//is=entity.getContent();
}
捕获(例外e)
{
CommonFunctions.writeLOG(ctx.getClass().toString(),e.toString());
showToast(ctx,“无法发布捕获的图像文件:”+e.toString());
}       
}
公共静态字节[]getCapturedVideoStream(上下文ctx,意图数据)
{       
尝试
{
AssetFileDescriptor videoAsset=ctx.getContentResolver().openAssetFileDescriptor(data.getData(),“r”);
FileInputStream fis=videoAsset.createInputStream();
ByteArrayOutputStream bos=新建ByteArrayOutputStream();
字节[]buf=新字节[1024];
尝试
{
对于(int readNum;(readNum=fis.read(buf))!=-1;)
bos.write(buf,0,readNum);
} 
捕获(IOE异常)
{
CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(),e.toString());
}
byte[]bytes=bos.toByteArray();
返回字节;
} 
捕获(IOE异常)
{
CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(),e.toString());
返回null;
}       
}
公共静态void postVideo(上下文ctx,字节[]ba)
{       
字符串sid=((MainActivity)ctx.mCaptureVideoHMap.get(“sid”).toString();
字符串ba1=Base64.encode(ba);
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“视频”,ba1));
for(迭代器iter=((MainActivity)ctx.mCaptureVideoHMap.entrySet().Iterator();iter.hasNext();)
{
Map.Entry=(Map.Entry)iter.next();
String key=(String)entry.getKey();
String value=(String)entry.getValue();
添加(新的BasicNameValuePair(键,值));
}
尝试
{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost-HttpPost=new-HttpPost(Config.MEDIA\u VIDEO\u PATH+”?AddFile=AddFile&SessionId=“+sid”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
//HttpEntity=response.getEntity();
}
捕获(例外e)
{
CommonFunctions.writeLOG(ctx.getClass().toString(),e.toString());
showtoos(ctx,“无法发布捕获的视频文件:”+e.toString());
}       
}
////用于读写图像和视频二进制的示例测试开始
公共静态布尔writeCaptureVideo(上下文ctx、意图数据)
{       
字符串文件名=((MainActivity)ctx.mcaptureMageHMap.get(“name”).toString();
字符串sid=((MainActivity)ctx.mcaptureMageHMap.get(“sid”).toString();
字符串路径=”;/((MainActivity)ctx).mmedipath;
尝试
{
AssetFileDescriptor videoAsset=ctx.getContentResolver().openAssetFileDescriptor(data.getData(),“r”);
FileInputStream fis=videoAsset.createInputStream();
File tmpFile=新文件(路径、文件名);
FileOutputStream fos=新的FileOutputStream(tmpFile);
字节[]buf=新字节[1024];
内伦;
而((len=fis.read(buf))>0)
{
fos.write(buf,0,len);
}       
fis.close();
fos.close();
返回true;
} 
捕获(IOE异常)
{
CommonFunctions.writeLOG(CacheImagesManager.class.getClass().toString(),e.toString());
返回false;