2013-07-03 1 views
1

마운트 된 Google Play APK 확장 OBB 파일 내의 파일에서 동영상을로드하려고합니다. 파일을 여는 동안 오류 (1, -2147483648) 오류 :MediaPlayer setDataSource to expansionFilePath가 작동하지 않습니다.

mMediaPlayer = new MediaPlayer(); 

StorageManager storageManager = (StorageManager)mParentActivity.getSystemService(Context.STORAGE_SERVICE); 

String obbPath = ExpansionHelper.getExpansionFilePath(mParentActivity); 
File movie = new File(storageManager.getMountedObbPath(obbPath), filename); 

Log.d(Constants.TAG, "Movie exists is " + movie.exists()); 

mMediaPlayer.setDataSource(obbPath); 

참고 :이 영화는 로그 '진정한'

E/MediaPlayer를 (27155)에 존재한다. 미디어 플레이어를 언로드 (지정되지 않은 미디어 플레이어 오류, -2147483648) E/MediaPlayer를 (27155) : 상태라는 중지 0 E/MediaPlayer를 (27155) : 오류 (-38, 0)

어떻게 재생할 수 있습니다 APK OBB 확장 파일 (zip 종류 아님)의 영화?

+0

이있어 동일한 문제 그러나 그것은 최신 버전에서 잘 작동하고 있습니다. 어떤 Android 버전에서이 문제가 발생 했습니까? – Gros

답변

1

이 방법이 효과가있는 이유는 정확히 모르겠지만 FileInputStream의 FileDescriptor를 제공하면 매력과 같은 것입니다!

FileInputStream fis = new FileInputStream(movie); 
mMediaPlayer.setDataSource(fis.getFD()); 
fis.close(); 
0

아, 그냥 볼이 질문에 잘 여기, 비 압축 파일에 관해서 어쨌든 버전을 압축된다

private static void setMediaPlayerDataSourceFromZip(MediaPlayer mediaPlayer, 
     String zipFileName, String fileNameInZip) throws IOException, 
     FileNotFoundException { 
    ZipResourceFile zip = new ZipResourceFile(zipFileName); 
    FileInputStream fis = new FileInputStream(zipFileName); 
    try { 
     FileDescriptor zipfd = fis.getFD(); 

     ZipEntryRO entry = zipFindFile(zip, fileNameInZip); 
     mediaPlayer.setDataSource(zipfd, entry.mOffset, 
       entry.mUncompressedLength); 
    } finally { 
     fis.close(); 
    } 
} 

private static ZipEntryRO zipFindFile(ZipResourceFile zip, String fileNameInZip) { 
    for (ZipEntryRO entry : zip.getAllEntries()) { 
     if (entry.mFileName.equals(fileNameInZip)) 
      return entry; 
    } 
    throw new RuntimeException(String.format("File \"%s\"not found in zip", fileNameInZip)); 
} 

사용법 : 인 2.3.x 안드로이드 버전에

setMediaPlayerDataSourceFromZip(mediaPlayer, 
    "/Some/zip/obb/withoutCompression.zip", 
    "path/within/zip/mymovie.mp4"); 
관련 문제