2014년 7월 8일 화요일

Everyplay in Unity for Android_ Everyplay Record를 활용하여 .mp4 생성.


Explain.
Everyplay사용시 share기능에 특화된 플러그인이기 때문에
자체 디바이스에 저장하는것이 불가능 한것으로 보여짐.
하지만, Everyplay를 활용하여 record진행시
.everyplaycache 라는 폴더에
mp4파일을 생성하는것을 확인.
이파일을 활용한 예를 정리.
(.xxxx등으로 .으로 시작하는 폴더의경우 대부분 캐시데이터를 저장하는용도로 사용.
그로인해 일반적인 방법으로는 접근불가.)

Flow.

Every play를 활용하여 record진행
cache폴더내에 .mp4파일 생성
생성된 .mp4파일 원하는 위치로 복제 후 사용.


How to used.
아래의 코드를 native jar plugin으로 만들어서
현재 Unityproject에 통합후
Everyplay stoprecord 호출 뒤
CopyFileFromEveryPlay를 호출해서 사용.

code.
package com.mycompany.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Environment;
import android.util.Log;

public class EveryPlayHelper {

 private static File sdcard = Environment.getExternalStorageDirectory();
 private static String parentDir = "/.EveryplayCache/myPackageName(e.g com.xxx.xxxx)/sessions";
 private static String saveDir = "/myVideo/";

 public static String CopyFileFromEveryPlay() throws IOException {
  File parent = new File(sdcard, parentDir);
  File videoFile = getFile(parent);
  
  FileChannel inputChannel = null;
  FileChannel outputChannel = null;
  

  if(videoFile.exists()){
   String fileName = "myVedio_";
   String currentDateandTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
   fileName += currentDateandTime;
   fileName += ".mp4";
   
   File dest = new File(sdcard, saveDir + fileName);
   
   try {
          inputChannel = new FileInputStream(videoFile).getChannel();
          outputChannel = new FileOutputStream(dest).getChannel();
          outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
  
      } finally {
          inputChannel.close();
          outputChannel.close();
      }
   
   Log.d("EveryPlay", "Copy End");
   
   return saveDir + fileName;
  }
  
  return null;
 }

 private static File getFile(File parentDir) {
  File[] files = parentDir.listFiles();
  File[] inFiles;
  for (File file : files) {
   if (file.isDirectory()) {
    Log.d("EveryPlay", "Found Complete Directory" + file.getName());
    inFiles = file.listFiles();
    for (File mfile : inFiles) {
     if (mfile.getName().endsWith(".mp4")) {
      Log.d("EveryPlay", "Found Complete File(.mp4) file name : " + mfile.getName());
      return mfile;
     }
    }
   }
  }
  return null;
 }
}
Categories: ,

0 개의 댓글:

댓글 쓰기