i'm trying to stream a wav file from a server. i used the sound stream function,
inside the callback function, i call the ReceiveDataTino to retrieve the data from the
server. the design of the ReceiveDataTino is to get 512 bytes at a time and combine it
to form a 4k bytes data because the device restarts when i retrieve 4k bytes directly.
this 4k bytes will then be set to the buffer of the sound stream callback. i was able
to run this successfully in the simulator. but when i tried it in T2, i only heard a
tick sound everytime the callback function is called. below is the actual code of the
ReceiveDataTino. i hope somebody could help me on this. thanks in advance.
static void ReceiveDataTino(char *bufferP, oeCallbackDataType* callbackDataP,
SndStreamRef stream)
{
Err err;
UInt16 result;
UInt16 bufLength;
char bufLen[6];
char *bufLenPtr = bufLen;
char *buf;
UInt16 tempBufIndex=0, i=0;
char *tempBuf = (char *)MemPtrNew(4096);
UInt8 ctr = 0;
Boolean stop = false;
if(! callbackDataP->stopna) {
// loop until the total received is 4096 bytes
do
{
aSendRequest(callbackDataP);
bufLength = 0;
StrCopy(bufLen, "");
bufLenPtr = bufLen;
// get the length of bytes to receive
while(
NetLibReceive (callbackDataP->netSocketRefNum, // Network library
callbackDataP->netSocketRef, // Socket reference
bufLenPtr, //
Buffer to receive
1,
// length of message
0, // Flags
NULL, // Destination address -- does
not apply to TCP sockets
0, // Length of destination
address
-1, // Timeout
&err // Error result
)
> 0 && *bufLenPtr != '\n') {
bufLenPtr++;
}
*bufLenPtr = '\0';
WinDrawChars("Bytes Received: ", StrLen("Bytes Received: "), 20, 100);
WinDrawChars(bufLen, StrLen(bufLen), 100, 100);
StrIToA(x, ctr);
WinDrawChars(x, StrLen(x), 12, 100);
// convert bufLen to integer
bufLength = StrAToI(bufLen);
// EOF
if(bufLength==-999) {
callbackDataP->stopna=true; return ;
}
buf = (char*)MemPtrNew(bufLength);
result = NetLibReceive (callbackDataP->netSocketRefNum, //
Network library
callbackDataP->netSocketRef, //
Socket reference
buf,
// Buffer to receive
bufLength,
// length of message
0, // Flags
NULL, // Destination address
-- does not apply to TCP sockets
0, // Length of
destination address
5*SysTicksPerSecond(), //
Timeout
&err // Error result
);
ctr ++;
// transfer received data to larger buffer.
for(i=0; i<bufLength; i++, tempBufIndex++)
tempBuf[tempBufIndex] = buf[i];
if(bufLength < 512)
stop = true;
MemPtrFree(buf);
} while(ctr < 8 && !stop);
MemPtrResize(tempBuf, tempBufIndex);
if (result == -1) {
SndStreamStop(stream);
aCloseSocket(callbackDataP);
}
else
{
// move to callback buffer pointer
if(bufferP)
MemMove(bufferP, tempBuf, tempBufIndex);
MemPtrFree(tempBuf);
}
}
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/