2016-02-27 154 views
1

我試圖使用panoramagl-android庫來顯示全景圖像。我的場景需要全景從互聯網加載,不能保存在android的本地res文件夾中,因爲我將擁有數百張圖片。無法從互聯網獲取圖像

我已經能夠成功地從res文件夾中加載全景jpeg,但未能對位於互聯網上的文件執行相同操作。

我想使用JSON加載全景圖像,因爲我已經提到過,我將有數百個圖像並通過代碼設置它們的熱點根本不可能。

這裏是res文件夾我的活動裝載JSON:

/** 
* This event is fired when root content view is created 
* @param contentView current root content view 
* @return root content view that Activity will use 
*/ 
@Override 
protected View onContentViewCreated(View contentView) 
{ 
    //Load layout 
    ViewGroup mainView = (ViewGroup)this.getLayoutInflater().inflate(R.layout.activity_main, null); 
    //Add 360 view 
    mainView.addView(contentView, 0); 

    loadSpherical2FromJson(); 

    //Return root content view 
    return super.onContentViewCreated(mainView); 
} 

private void loadSpherical2FromJson() { 
    try 
    { 
     PLILoader loader; 
     loader = new PLJSONLoader("res://raw/json_spherical2"); 
     this.load(loader, true, new PLTransitionBlend(2.0f)); 
    } 
    catch(Throwable e) 
    { 
     Toast.makeText(this.getApplicationContext(), "Error: " + e, Toast.LENGTH_SHORT).show(); 
    } 
} 

我的JSON是這樣的:

{ 
    // "urlBase": "res://", 
    "urlBase": "http://", 
    "type": "spherical2", 
    "keep": "all", 
    "images": 
    { 
    // "preview": "raw/casabella_hall_preview", 
    // "image": "raw/casabella_hall_2048" 
    "preview": "statichost.herokuapp.com/panoramagl/casabella_hall_preview.jpg", 
    "image": "statichost.herokuapp.com/panoramagl/casabella_hall_2048.jpg" 
    }, 
    "camera": 
    { 
    "keep": "all|~atvRange|~rotation|~fov", 
    "atvMin": -90.0, 
    "atvMax": 90.0, 
    "vLookAt": 0.0, 
    "hLookAt": 170.0 
    }, 
    "hotspots": 
    [ 
    { 
     "id": 1, 
     "atv": 0.0, 
     "ath": 170.0, 
     "width": 0.05, 
     "height": 0.05, 
     // "image": "raw/hotspot", 
     "image": "statichost.herokuapp.com/panoramagl/hotspot.png", 
     "alpha": 0.8, 
     "overAlpha": 1.0, 
     "onClick": "lookAt(0.0, 90.0, true);" 
    } 
    ] 
} 

對資源的註釋掉的代碼://工作正常但是HTTP://不管用。我還需要從互聯網獲取這個JSON數據(但一次只能做一件事)。

這裏是整個應用程序一個GitHub庫:https://github.com/ishanatmuz/PanoramaGL-Test/tree/Spherical2Json

請幫助。

UPDATE:

早些時候我得到Rejecting re-init on previously-failed class ....的信息,但不作爲logcat的錯誤,所以我沒有懷疑這可能是問題。 Anyhoo我添加commons-httpclient-3.1.jar在libs文件夾中,以消除它,假設可能是問題。但是,現在,當我運行應用程序時,我看到一個循環加載器動畫,指示正在加載,但是我仍然看到黑屏。在網絡監視器中,我仍然看不到任何網絡請求被觸發。

我已經更新了github回購中的代碼。

回答

0

我找出問題所在。我正在將INTERNET權限放在錯誤位置的清單中。它正在工作。

代碼的工作版本在GitHub倉庫中更新。 但是,我將鏈接代碼版本與Android中的PanoramaGl集成類似的問題的其他人。

  1. PanoramaGL整合使用的jar文件source code
  2. PanoramaGL整合利用圖書館的源source code

我想提一提,我不得不將一些庫文件和一些LIB膠水要刪除的文件的複製文件,從而減少APK的大小。

在我的文件移動。我發現使用jar文件(上面提到的方法1)作爲庫給我一個2.8MB的APK。並使用源代碼(上面提到的方法2)給我一個2.6 M的APK。

用戶可能考慮的另一件事是方法計數,因爲Android有一個upper limit on method count of 65536

+0

嗨,我正在嘗試使用您在上面的答案中提供的代碼實現全景。當我嘗試通過本地json文件實現立方體類型時,我得到一個黑色屏幕,圖像大小爲1024x1024。任何想法爲什麼我會看到黑屏? –

+0

如果您向我提供代碼和所有文件,我只能嘗試提供幫助。 – Ishan

+0

嘿謝謝你提供幫助。當我在調試時,不知何故設法使它工作.. :) –