A Guide To Streaming

The internet is excellent for finding the content you want, and as speeds have increased so has the media available for consumption. Many of us remember the days when it took a day to download a song, which seems ludicrous today considering you can now instantly watch HD video, simply by pressing play.

For a lot of people streaming music and video is still an alien concept and don’t know the best sites and to find what they want. In reality, streaming is one of the easiest ways to find and watch exactly what you want, when you want, without having to have recording technology like a DVD recorder or ancient VHS!

Fast Connection

To effectively stream video in particular you will need a good, fast broadband connection in your home, rather than mobile or dial-up internet. It makes no difference whether you connect to the internet wirelessly or by using an Ethernet cable, as both will allow you to watch video with very little interruption.

If you are not satisfied with your connection then you should do a broadband speed test to find how fast your internet is running and then compare it with other providers in your area. Some providers also offer super-fast fibre optic broadband which should never have any trouble with streaming videos, although this comes at a price.

There are other factors that can affect the speed of your connection, such as the distance you are from the telephone exchange, how many people are connecting to the internet in your house and whether you are using it at peak times.

Streaming TV content

Many of the major TV channels offer a free, on-demand internet streaming service that allows you to choose exactly what you want to watch and when you want to watch it. All of them allow you to watch live TV as well as programs that have already aired, but some networks put limitations on what is available, such as only letting you view a program for a certain time period after it has aired. Other video streaming sites are starting to get more TV content as it becomes widely available.

Streaming Music

Music files are much smaller than video files so can be streamed with a slower connection. This makes it perfect for listening on the go with on-demand music services available for monthly subscriptions. Many artists nowadays will pre-release their new singles and albums for streaming on the internet so it is also a great way to hear the music you love first.

Whilst it may be a new concept for some, streaming music and video on the internet is actually very easy and is the best way to watch the things that you love, at the time that is most convenient for you.

Donations appreciated. Every little $ helps. Or click Google +1.

How To Load Text File From Assets Folder In Android

When you place files in the assets folder and you want to use them in your Android app, you normally access them via streams.

Let us say you want to load a text file. How can one go about it?

This method will convert your assets text file into a String object.

public static String convertStreamToString(InputStream is) throws IOException {
    String text = null;
    try {
        int size = is.available();
    	byte[] buffer = new byte[size];
    	is.read(buffer);
    	is.close();
    	text = new String(buffer);
    } catch (Exception e) { }
    return text;
}

To use this method in your Activity, you do this.

String str = convertStreamToString(getAssets().open("sample.txt"));

Donations appreciated. Every little $ helps. Or click Google +1.

Java: Convert Stream To Byte[]

Say you call an HTTP request that returns a byte array which contains a binary file, how would you do this? First things first. Access it using an HttpURLConnection object. Once you have connected to the URL, get the InputStream object and that is when you will be able to convert the stream into a byte array. Check the code below.

URL u = new URL("MY URL");
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
if (contentType.startsWith("text/") || contentLength == -1) {
    throw new IOException("This is not a binary file.");
}
InputStream raw = uc.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
    bytesRead = in.read(data, offset, data.length - offset);
    if (bytesRead == -1) break;
    offset += bytesRead;
}
in.close();

The data variable is the byte array. You can then do whatever you like (e.g. saving it as a binary file) after you have retrieved the byte array object.

Donations appreciated. Every little $ helps. Or click Google +1.

Related Posts Plugin for WordPress, Blogger...