//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2012 Freshplanet (http://freshplanet.com | opensource@freshplanet.com)
//  
//  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 com.freshplanet.ane.AirAACPlayer;

import java.util.HashMap;
import java.util.Map;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.view.ViewGroup;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.freshplanet.ane.AirAACPlayer.functions.*;

public class ExtensionContext extends FREContext
{
    private MediaPlayer _mediaPlayer;
    private String _mediaUrl;
    private boolean _isLoaded;
    
    @Override
    public void dispose() {}

    @Override
    public Map<String, FREFunction> getFunctions()
    {
        Map<String, FREFunction> functions = new HashMap<String, FREFunction>();
        
        functions.put("loadUrl", new LoadUrlFunction());
        functions.put("play", new PlayFunction());
        functions.put("pause", new PauseFunction());
        functions.put("stop", new StopFunction());
        functions.put("close", new CloseFunction());
        functions.put("getLength", new GetLengthFunction());
        functions.put("getProgress", new GetProgressFunction());
        
        return functions;
    }
    
    public void setMediaUrl( String url ) 
    {
    	_mediaUrl = url;
    }
    
    public String getMediaUrl() 
    {
    	return _mediaUrl;
    }

    public boolean isLoaded()
    {
        return _isLoaded;
    }

    public void setIsLoaded(boolean isLoaded)
    {
        _isLoaded = isLoaded;
    }
    
    public ViewGroup getRootContainer()
    {
        return (ViewGroup)((ViewGroup)getActivity().findViewById(android.R.id.content)).getChildAt(0);
    }
    
    public MediaPlayer getPlayer()
    {
        if (_mediaPlayer == null)
        {
            _mediaPlayer = new MediaPlayer();
            _mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        }
        
        return _mediaPlayer;
    }
    
    public void setPlayer(MediaPlayer player)
    {
        this._mediaPlayer = player;
    }
}

@@ -1197,16 +1197,171 @@
 ntext%0A%7B%0A
+    public static final String LOADING = %22LOADING%22;%0A    public static final String PREPARED = %22PREPARED%22;%0A    public static final String ERROR = %22ERROR%22;%0A%0A
     priv
@@ -1416,24 +1416,25 @@
  _mediaUrl;%0A
+%0A
     private 
@@ -1437,25 +1437,21 @@
 ate 
-boolean _isLoaded
+String _state
 ;%0A  
@@ -2094,191 +2094,35 @@
   %7D%0A
-    %0A    public void setMediaUrl( String url ) %0A    %7B%0A    %09_mediaUrl = url;%0A    %7D%0A    %0A    public String getMediaUrl() %0A    %7B%0A    %09return _mediaUrl;%0A    %7D%0A%0A    public boolean isLoaded
+%0A    public String getState
 ()%0A 
@@ -2142,24 +2142,21 @@
 return _
-isLoaded
+state
 ;%0A    %7D%0A
@@ -2179,69 +2179,56 @@
  set
-IsLoaded(boolean isLoaded)%0A    %7B%0A        _isLoaded = isLoaded
+State(String state)%0A    %7B%0A        _state = state
 ;%0A  

Change extension context… - adding player states - removing isLoaded - removing getUrl