레이블이 EveryPlay인 게시물을 표시합니다. 모든 게시물 표시
레이블이 EveryPlay인 게시물을 표시합니다. 모든 게시물 표시

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;
 }
}

Everyplay in Unity with NGUI_Everyplay HUD camera사용시.


삽질ing...

Everyplay를 활용하여 작업시
NGUI를 사용하고있는경우
NGUI의 일부분만 지우고싶어서 그부분에 해당하는 Camera에
Everyplay HUD camera설정을 적용시
NGUI모두 record가 안되는 현상이발생.
이럴경우
record할 UI에만 record용으로 camera를 따로 배치해주어야 
record가 제대로 동작하는것을 확인.

NGUI를 사용시 Everyplay를 함께 사용하면 발생하는 문제로 보이며
Unity자체의 UI system을 사용할때는 발생하지 않는것으로 파악됨.