开发者

Setting up webserver to access media content for Android, Blackberry, and iPhone applications

We have a multimedia application that allows users to download wallpapers and watch video clips. As of now we just have a limited number of pictures and videos stored within the application bundle (which drives the app size up). Now we are going to set up a webserver to house the content, and the application will be accessing the content over the internet.

I have never worked on or setup a webserver, but our client said h开发者_如何学JAVAe would rather add the content to their server anyways. Is there a certain way it needs to be setup? Is all I need is a url to access each picture and video? I apologize if I didn't explain that too good. I'm not too familiar with the server end of things. Thanks for any help.

We will have over 100 pictures and probably around 20 video clips. Does each image and video clip need to be setup with its own url? Or is there another way to do it?


All you need is the URL for the resource, and an HTTP library to download it. If your client provides the URLs then it can be manually coded in. Or if there are too many, or if the client intends to add more videos as time goes on then you might think about having an index of all the URLs, maybe in a database or an XML file on the web server.

As for the server, all the clients needs is a normal HTTP server, such as Apache.

Sorry if I did not understand your question.


Just wanted to post another solution. But you could just write a server side script that searches for the file names. This saves you from creating a new page for every resource and saves you from having to deal with that many urls. In the app, access the script and pass in the fileName (http://www.yourserver.com/getFile.php?file=fileName). Thanks for the help Alex. This was an answer provided by "jprofit" on another forum. Thanks to him too. Alex's solution may be easier if you have a few resources, but for as many as I'm dealing with, this is the way we are going with.


first simply create VedioDownloader class and pass the url for download the vedio and call this class in thread in mainactivity

 import android.os.Environment; 
 import android.util.Log;

public class VedioDownloader implements Runnable {
String vedio_URL = "http://daily3gp.com/vids/747.3gp";
//if download image then simply pass image url such as
 //String image_URL = "http://www.appliconic.com/screen.jpg";
public void run() {
    // TODO Auto-generated method stub
    HttpURLConnection conn = null;
    URL url = null;
    try {
        url = new URL(vedio_URLL);
    } catch (MalformedURLException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    try {
        conn = (HttpURLConnection) url.openConnection();
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    conn.setDoInput(true);

    try {
        conn.connect();
        Log.d("Connection", "Connection Established");
        InputStream input = conn.getInputStream();
        File storagePath = Environment.getExternalStorageDirectory();
        OutputStream output = new FileOutputStream(new File(storagePath,
                "vedio.3gp"));
        Log.d("1", "1");
        byte[] buffer = new byte[input.available()];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
            output.write(buffer, 0, bytesRead);
        }
        Log.d("2", "2");
        output.close();
        input.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

mainactivity class

 public class MainActivity extends Activity {


   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       Log.d("aftar thread","befor thread");
    Thread objThread=new Thread(new VedioDownloader());
    objThread.start();
      Log.d("aftar thread","fater thread");
   }     
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜