Back to project page mclib.
The source code is released under:
Apache License, Version 2.0 FoundationProjectsPeopleGet InvolvedDownloadSupport ApacheHome ? Licenses Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITION...
If you think the Android project mclib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* Copyright 2012 Mikhail Chabanov//from ww w . j a v a2 s . c om Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package mc.lib.video; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import mc.lib.stream.StreamHelper; import android.content.Context; import android.util.Log; public abstract class BasicVideoPlayer implements IVideoPlayer { private static final String LOGTAG = VideoViewPlayer.class.getSimpleName(); protected Context context; public BasicVideoPlayer(Context context) { super(); this.context = context; } public void play(File f) { if(f.exists() && f.canRead()) { play(f.getAbsoluteFile()); } else { Log.e(LOGTAG, "File " + f + "not found"); } } public void play(int rawResId) { try { InputStream is = context.getResources().openRawResource(rawResId); play(is); StreamHelper.close(is); } catch(Exception e) { Log.e(LOGTAG, "Cannot open raw resource:" + rawResId, e); return; } } public void play(InputStream is) { String tmpFile; try { tmpFile = context.getCacheDir() + "/video.tmp"; Runtime.getRuntime().exec("chmod 644 " + tmpFile); FileOutputStream fos = new FileOutputStream(tmpFile); StreamHelper.copyStream(is, fos); StreamHelper.close(fos); } catch(Exception e) { Log.e(LOGTAG, "Cannot create cache file.", e); return; } play(tmpFile); } // XXX Fix it: Doesn't work properly public void play(FileDescriptor fd) { FileInputStream fis = new FileInputStream(fd); play(fis); StreamHelper.close(fis); } }