You Are Here:

Community: Developer Discussion Boards

#1 Old problem wih wav media player to support buffering - 2009-04-13, 20:59

Join Date: Mar 2009
Posts: 25
hamada200700
Offline
Registered User
But when am adding some modifications
on the class of wavplayer
to support the buffering concept
it doesn't work
and an error happen
plz anyone try to help me
to solve it[/size][/b]

package playsound;

import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.media.*;
import java.util.Vector;

public class WavPlayer
extends Form
implements CommandListener , PlayerListener {
Command exitCmd = new Command("Exit", Command.EXIT, 1);
Command backCmd = new Command("Back", Command.BACK, 2);
Command stopCmd = new Command("Stop", Command.SCREEN, 3);
Command startCmd = new Command("Start", Command.SCREEN, 3);
PlaysoundMIDlet myPlaysoundMIDlet;
Displayable parent;
Player player;
Thread bufferingThread;
Thread playingThread;
boolean startPlayingThread;
Vector audioByteArrays;

public WavPlayer(PlaysoundMIDlet myPlaysoundMIDlet, Displayable parent) {
super("Displayable Title");
this.myPlaysoundMIDlet = myPlaysoundMIDlet;
this.parent = parent;
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(exitCmd);
addCommand(backCmd);
addCommand(stopCmd);
addCommand(startCmd);
play();
}

private void play() {
//start buffering
bufferingThread = new Thread() {
public void run() {
// thread action goes here
try {
InputStream is = getClass().getResourceAsStream("/res/music.wav");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
int b;
while ( ( (b = is.read()) != -1)) {
baout.write(b);
if (baout.size() > 1000) {
baout.close();
audioByteArrays.addElement(baout.toByteArray());
baout = new ByteArrayOutputStream();
}
}
is.close();
}
catch (IOException ex) {
}
}
};
bufferingThread.start();

//playing playingThread
playingThread = new Thread() {
public void run() {
// thread action goes here startPlayingThread
int currentplayedArray = 0;
while (audioByteArrays.size() < currentplayedArray) {
try {
Thread.sleep(500);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
}
try {
//InputStream is = getClass().getResourceAsStream("/res/music.wav");
ByteArrayInputStream bain =
new ByteArrayInputStream( (byte[])
audioByteArrays.elementAt(currentplayedArray) );
player = Manager.createPlayer(bain, "audio/X-wav");
player.start();

}
catch (Exception ex) {
}
}
};
playingThread.start();
}

public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if (command == backCmd) {
Display.getDisplay(myPlaysoundMIDlet).setCurrent(parent);
}
else if (command == exitCmd) {
try {
player.stop();
}
catch (MediaException ex) {
ex.printStackTrace();
}
// stop the MIDlet
PlaysoundMIDlet.quitApp();
}
else if (command == stopCmd) {
try {
player.stop();
}
catch (MediaException ex) {
ex.printStackTrace();
}
}
else if (command == startCmd) {
try {
player.start();
}
catch (MediaException ex) {
ex.printStackTrace();
}
}
}

/**
* playerUpdate
*
* @param player Player
* @param string String
* @param object Object
*/
public void playerUpdate(Player player, String event, Object eventData) {
if (event == (PlayerListener.VOLUME_CHANGED)) {
//VolumeControl vc = (VolumeControl) eventData;
//updateDisplay("Volume Changed to: " + vc.getLevel());
//if (vc.getLevel() > 60) {
// updateDisplay("Volume higher than 60 is too loud");
// vc.setLevel(60);
//}
} else if (event == (PlayerListener.STOPPED)) {
//updateDisplay("Player paused at: " + (Long) eventData);
} else if (event == (PlayerListener.STARTED)) {
//updateDisplay("Player started at: " + (Long) eventData);
} else if (event == (PlayerListener.END_OF_MEDIA)) {
//updateDisplay("Player reached end of loop.");
} else if (event == (PlayerListener.CLOSED)) {
//updateDisplay("Player closed.");
} else if (event == (PlayerListener.ERROR)) {
//updateDisplay("Error Message: " + (String) eventData);
}
}

}
Reply With Quote

#2 Old Thumbs up Re: problem wih wav media player to support buffering - 2009-04-14, 07:26

Join Date: Sep 2008
Posts: 1,195
Location: DELHI
Send a message via Yahoo to jitu_goldie
jitu_goldie's Avatar
jitu_goldie
Offline
Forum Nokia Champion
explain motive of ur application. what u want to do?


thanks,
jitu_goldie..

KEEP TRYING..
Reply With Quote

#3 Old Re: problem wih wav media player to support buffering - 2009-04-14, 15:47

Join Date: Apr 2009
Posts: 89
Osam
Offline
Regular Contributor
Hi,

Can u tell me more about your problem. After i can help u..

Thanks
Osam
Reply With Quote

#4 Old Re: problem wih wav media player to support buffering - 2009-04-15, 08:25

Join Date: Jun 2007
Posts: 534
Location: Mumbai
Send a message via Yahoo to prakash.raman
prakash.raman's Avatar
prakash.raman
Offline
Super Contributor
what kind of buffering you are trying to do? In place of putting all your code if u can specify more about your issue it would be help full.


au revoir
Prakash Raman
Reply With Quote

#5 Old Re: problem wih wav media player to support buffering - 2009-04-15, 08:35

Join Date: Mar 2009
Posts: 25
hamada200700
Offline
Registered User
hi for all
before u g to help me
read the thread which called
""is this player playing right""
on the open discussion
this 3 parts
as wav media player
and it run by a nice way

Then am add some modifications on the part of wavplyer
to support buffering
by adding two threads

which will be shown in th following
and when am run it
it doesn't run
and appear an error!!!
plz hlp me

package playsound;

import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.media.*;
import java.util.Vector;

public class WavPlayer
extends Form
implements CommandListener , PlayerListener {
Command exitCmd = new Command("Exit", Command.EXIT, 1);
Command backCmd = new Command("Back", Command.BACK, 2);
Command stopCmd = new Command("Stop", Command.SCREEN, 3);
Command startCmd = new Command("Start", Command.SCREEN, 3);
PlaysoundMIDlet myPlaysoundMIDlet;
Displayable parent;
Player player;
Thread bufferingThread;
Thread playingThread;
boolean startPlayingThread;
Vector audioByteArrays;

public WavPlayer(PlaysoundMIDlet myPlaysoundMIDlet, Displayable parent) {
super("Displayable Title");
this.myPlaysoundMIDlet = myPlaysoundMIDlet;
this.parent = parent;
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(exitCmd);
addCommand(backCmd);
addCommand(stopCmd);
addCommand(startCmd);
play();
}

private void play() {
//start buffering
bufferingThread = new Thread() {
public void run() {
// thread action goes here
try {
InputStream is = getClass().getResourceAsStream("/res/music.wav");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
int b;
while ( ( (b = is.read()) != -1)) {
baout.write(b);
if (baout.size() > 1000) {
baout.close();
audioByteArrays.addElement(baout.toByteArray());
baout = new ByteArrayOutputStream();
}
}
is.close();
}
catch (IOException ex) {
}
}
};
bufferingThread.start();

//playing playingThread
playingThread = new Thread() {
public void run() {
// thread action goes here startPlayingThread
int currentplayedArray = 0;
while (audioByteArrays.size() < currentplayedArray) {
try {
Thread.sleep(500);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
}
try {
//InputStream is = getClass().getResourceAsStream("/res/music.wav");
ByteArrayInputStream bain =
new ByteArrayInputStream( (byte[])
audioByteArrays.elementAt(currentplayedArray) );
player = Manager.createPlayer(bain, "audio/X-wav");
player.start();

}
catch (Exception ex) {
}
}
};
playingThread.start();
}

public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if (command == backCmd) {
Display.getDisplay(myPlaysoundMIDlet).setCurrent(parent);
}
else if (command == exitCmd) {
try {
player.stop();
}
catch (MediaException ex) {
ex.printStackTrace();
}
// stop the MIDlet
PlaysoundMIDlet.quitApp();
}
else if (command == stopCmd) {
try {
player.stop();
}
catch (MediaException ex) {
ex.printStackTrace();
}
}
else if (command == startCmd) {
try {
player.start();
}
catch (MediaException ex) {
ex.printStackTrace();
}
}
}

/**
* playerUpdate
*
* @param player Player
* @param string String
* @param object Object
*/
public void playerUpdate(Player player, String event, Object eventData) {
if (event == (PlayerListener.VOLUME_CHANGED)) {
//VolumeControl vc = (VolumeControl) eventData;
//updateDisplay("Volume Changed to: " + vc.getLevel());
//if (vc.getLevel() > 60) {
// updateDisplay("Volume higher than 60 is too loud");
// vc.setLevel(60);
//}
} else if (event == (PlayerListener.STOPPED)) {
//updateDisplay("Player paused at: " + (Long) eventData);
} else if (event == (PlayerListener.STARTED)) {
//updateDisplay("Player started at: " + (Long) eventData);
} else if (event == (PlayerListener.END_OF_MEDIA)) {
//updateDisplay("Player reached end of loop.");
} else if (event == (PlayerListener.CLOSED)) {
//updateDisplay("Player closed.");
} else if (event == (PlayerListener.ERROR)) {
//updateDisplay("Error Message: " + (String) eventData);
}
}

}
Reply With Quote

#6 Old Thumbs up Re: problem wih wav media player to support buffering - 2009-04-15, 14:29

Join Date: Sep 2008
Posts: 1,195
Location: DELHI
Send a message via Yahoo to jitu_goldie
jitu_goldie's Avatar
jitu_goldie
Offline
Forum Nokia Champion
what error is coming with this code..


thanks,
jitu_goldie..

KEEP TRYING..
Reply With Quote

#7 Old Re: problem wih wav media player to support buffering - 2009-04-15, 14:46

Join Date: Jun 2008
Posts: 96
Send a message via AIM to sharvan1981
sharvan1981's Avatar
sharvan1981
Offline
Regular Contributor
hi,

what is going on when u execute this code.I thing u are getting exception ,try to explain all thinks.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
No audio over bluetooth HFP, but standard media player works (using CMdaAudioPlayerU) Andrey.Tetyuev General Symbian C++ 7 2009-08-19 09:30
Problem creating player on N81 lamiaaMB Mobile Java Media (Graphics & Sounds) 6 2008-06-24 20:03
Nokia 6630 & 6680 media player Gordon_Chen Streaming and Video 1 2007-06-12 19:19
Nokia 3250 Media Player Problems smash555 General Discussion 2 2007-02-26 13:03
help with sound media player with animated pictures larry_ger Mobile Java General 0 2003-02-25 11:50

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ