dcsimg
.PNG with Audio
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yogesh_Chugh
Posted On:   Wednesday, September 24, 2003 04:22 AM

Hi List..
I just want to make an application in which i want to display a still image like any .png picture on the mibile display with some background music (any .wav or .mp3).
How can I make that application? Is it possible to get picture of any other format rather than .png?
Can anyone give me any code or some link where i cud get some coding help...Please help me out...
Thanks in advance...

Re: .PNG with Audio

Posted By:   Anonymous  
Posted On:   Friday, October 10, 2003 09:23 AM

Hi,

it is not possible to get picture of any other format rather than .png.

To play sound, here is a class definition that can maybe help you:




import java.io.*;

import javax.microedition.media.*;



public class SoundPlayer{

private InputStream inputStream;

private String type = new String();



public SoundPlayer(String resource, String type) throws IOException{

if (resource == null || resource.length() == 0 || type == null || type.length() == 0)

throw new IOException("Fichier inexistant");

inputStream = getClass().getResourceAsStream(resource);

if (inputStream == null)

throw new IOException("Ressource " + resource + " inexistante");

else{

this.type = type;

return;

}

}



public SoundPlayer(InputStream inputstream, String type) throws IOException {

if (inputstream == null || type == null || type.length() == 0) {

throw new IOException("InputStream null");

}

else{

this.inputStream = inputstream;

this.type = type;

return;

}

}



void play(){

try {

Player p = Manager.createPlayer(inputStream, type);

p.start();

}

catch (MediaException pe) {}

catch (Exception ioe) {}

}



public void close() throws IOException {

if (inputStream != null) {

inputStream.close();

inputStream = null;

}

}

}






and to use it in any other class:

declare a method to play the sound:


void playSoundMySound(){

try{

SoundPlayer s = new SoundPlayer("/mysound.wav", "audio/x-wav");

s.play();

}

catch(Exception e){}

}




and call it when tou want your sound to be played:


playSoundMySound();




I hope that this could help you...



PS: excuse my very bad english...
About | Sitemap | Contact