Movie.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.graphics; 18 19import java.io.InputStream; 20import java.io.FileInputStream; 21 22public class Movie { 23 private final int mNativeMovie; 24 25 private Movie(int nativeMovie) { 26 if (nativeMovie == 0) { 27 throw new RuntimeException("native movie creation failed"); 28 } 29 mNativeMovie = nativeMovie; 30 } 31 32 public native int width(); 33 public native int height(); 34 public native boolean isOpaque(); 35 public native int duration(); 36 37 public native boolean setTime(int relativeMilliseconds); 38 39 public native void draw(Canvas canvas, float x, float y, Paint paint); 40 41 public void draw(Canvas canvas, float x, float y) { 42 draw(canvas, x, y, null); 43 } 44 45 public static native Movie decodeStream(InputStream is); 46 public static native Movie decodeByteArray(byte[] data, int offset, 47 int length); 48 49 public static Movie decodeFile(String pathName) { 50 InputStream is; 51 try { 52 is = new FileInputStream(pathName); 53 } 54 catch (java.io.FileNotFoundException e) { 55 return null; 56 } 57 return decodeTempStream(is); 58 } 59 60 private static Movie decodeTempStream(InputStream is) { 61 Movie moov = null; 62 try { 63 moov = decodeStream(is); 64 is.close(); 65 } 66 catch (java.io.IOException e) { 67 /* do nothing. 68 If the exception happened on open, moov will be null. 69 If it happened on close, moov is still valid. 70 */ 71 } 72 return moov; 73 } 74} 75