2016-02-27 156 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

嘿谢谢你提供帮助。当我在调试时,不知何故设法使它工作.. :) –