// Path: app/src/main/java/javax/microedition/util/ContextHolder.java
// public class ContextHolder {
// 
// 	private static final String tag = "ContextHolder";
// 
// 	private static MainActivity context;
// 	private static ArrayList<ActivityResultListener> resultListeners = new ArrayList<ActivityResultListener>();
// 	private static LayoutInflater inflater;
// 
// 	public static void setContext(MainActivity cx) {
// 		context = cx;
// 		inflater = LayoutInflater.from(cx);
// 	}
// 
// 	public static Context getContext() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getContext()");
// 		}
// 		return context;
// 	}
// 
// 	public static LayoutInflater getInflater() {
// 		return inflater;
// 	}
// 
// 	public static InputStream getResourceAsStream(String filename) {
// 		if (filename.startsWith("/")) {
// 			filename = filename.substring(1);
// 		}
// 
// 		try {
// 			return getContext().getAssets().open(filename);
// 		} catch (IOException e) {
// 			Log.d(tag, "getResourceAsStream err: " + e.getMessage());
// 			return null;
// 		}
// 	}
// 
// 	public static File getCacheDir() {
// 		if (Environment.MEDIA_MOUNTED.equals(Environment
// 				.getExternalStorageState())) {
// 			return getContext().getExternalCacheDir();
// 		} else {
// 			return getContext().getCacheDir();
// 		}
// 	}
// 
// 	public static int getRequestCode(String requestString) {
// 		return requestString.hashCode() & 0x7FFFFFFF;
// 	}
// 
// 	public static MainActivity getActivity() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getActivity()");
// 		}
// 		return context;
// 	}
// 
// 	public static void addActivityResultListener(ActivityResultListener listener) {
// 		if (!resultListeners.contains(listener)) {
// 			resultListeners.add(listener);
// 		}
// 	}
// 
// 	public static void removeActivityResultListener(
// 			ActivityResultListener listener) {
// 		resultListeners.remove(listener);
// 	}
// 
// 	public static void notifyOnActivityResult(int requestCode, int resultCode,
// 			Intent data) {
// 		for (ActivityResultListener listener : resultListeners) {
// 			listener.onActivityResult(requestCode, resultCode, data);
// 		}
// 	}
// }


import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import javax.microedition.util.ContextHolder;
import android.content.res.AssetFileDescriptor;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;

/*
 * Copyright 2012 Kulikov Dmitriy
 *
 * 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 javax.microedition.media;




public class DataSource
{
	protected String locator;
	protected File file;
	
	protected FileInputStream stream;
	protected AssetFileDescriptor asset;
	protected FileDescriptor descriptor;
	protected long offset;
	protected long length;
	
	public DataSource(String locator)
	{
		this.locator = locator;
	}
	
	public DataSource(File file)
	{
		this.file = file;
	}
	
	public void open() throws IOException
	{
		if(descriptor == null)
		{
			if(locator != null && !locator.contains("://"))
			{
				if(locator.startsWith("/"))
				{
					locator = locator.substring(1);
				}
				

// Path: app/src/main/java/javax/microedition/util/ContextHolder.java
// public class ContextHolder {
// 
// 	private static final String tag = "ContextHolder";
// 
// 	private static MainActivity context;
// 	private static ArrayList<ActivityResultListener> resultListeners = new ArrayList<ActivityResultListener>();
// 	private static LayoutInflater inflater;
// 
// 	public static void setContext(MainActivity cx) {
// 		context = cx;
// 		inflater = LayoutInflater.from(cx);
// 	}
// 
// 	public static Context getContext() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getContext()");
// 		}
// 		return context;
// 	}
// 
// 	public static LayoutInflater getInflater() {
// 		return inflater;
// 	}
// 
// 	public static InputStream getResourceAsStream(String filename) {
// 		if (filename.startsWith("/")) {
// 			filename = filename.substring(1);
// 		}
// 
// 		try {
// 			return getContext().getAssets().open(filename);
// 		} catch (IOException e) {
// 			Log.d(tag, "getResourceAsStream err: " + e.getMessage());
// 			return null;
// 		}
// 	}
// 
// 	public static File getCacheDir() {
// 		if (Environment.MEDIA_MOUNTED.equals(Environment
// 				.getExternalStorageState())) {
// 			return getContext().getExternalCacheDir();
// 		} else {
// 			return getContext().getCacheDir();
// 		}
// 	}
// 
// 	public static int getRequestCode(String requestString) {
// 		return requestString.hashCode() & 0x7FFFFFFF;
// 	}
// 
// 	public static MainActivity getActivity() {
// 		if (context == null) {
// 			throw new IllegalStateException(
// 					"call setContext() before calling getActivity()");
// 		}
// 		return context;
// 	}
// 
// 	public static void addActivityResultListener(ActivityResultListener listener) {
// 		if (!resultListeners.contains(listener)) {
// 			resultListeners.add(listener);
// 		}
// 	}
// 
// 	public static void removeActivityResultListener(
// 			ActivityResultListener listener) {
// 		resultListeners.remove(listener);
// 	}
// 
// 	public static void notifyOnActivityResult(int requestCode, int resultCode,
// 			Intent data) {
// 		for (ActivityResultListener listener : resultListeners) {
// 			listener.onActivityResult(requestCode, resultCode, data);
// 		}
// 	}
// }


// Path: app/src/main/java/javax/microedition/media/DataSource.java
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import javax.microedition.util.ContextHolder;
import android.content.res.AssetFileDescriptor;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;

/*
 * Copyright 2012 Kulikov Dmitriy
 *
 * 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 javax.microedition.media;




public class DataSource
{
	protected String locator;
	protected File file;
	
	protected FileInputStream stream;
	protected AssetFileDescriptor asset;
	protected FileDescriptor descriptor;
	protected long offset;
	protected long length;
	
	public DataSource(String locator)
	{
		this.locator = locator;
	}
	
	public DataSource(File file)
	{
		this.file = file;
	}
	
	public void open() throws IOException
	{
		if(descriptor == null)
		{
			if(locator != null && !locator.contains("://"))
			{
				if(locator.startsWith("/"))
				{
					locator = locator.substring(1);
				}
				

				asset = ContextHolder.getContext().getAssets().openFd(locator);
