Sponsored Content
Top Forums Programming problem with playing a song using mplayer Post 302228658 by shashi on Monday 25th of August 2008 06:56:45 AM
Old 08-25-2008
Question problem with playing a song using mplayer

Hi all,
I have an application program which keeps reading an audio file from a directory one after the other , once a file is chosen it keeps sending data in terms of 60000 bytes to a specified socket. This is written into another file "x.mp3" and mplayer is called. Again next 60000 bytes are read and same procedure is followed till end of file.
here is my code which does the above work

Code:
#include<stdio.h>
#include<dirent.h>
#include<string.h>
#include<errno.h>
#include<sys/types.h>
#include<stdlib.h>
#include <arpa/inet.h>  /* for sockaddr_in and inet_addr() */
#include <unistd.h>     /* for close() */
#define FALSE 0
#define TRUE !FALSE
  void DieWithError(char *errorMessage);  
int main()
{
      DIR *d = opendir("sun");
      struct dirent *ent;
      int count = 0,x;
      char filePath[20];
      const char filepa[20]="sun/";
      unsigned char funcall[100] = "mplayer "; 
      FILE *fp,*fp1;
      int sock;                        /* Socket descriptor */ 
      struct sockaddr_in echoServAddr; /* Echo server address */
      unsigned short echoServPort;        /*  Echo server port */
      char song[20];
      char temp[20];
      char songname[20] = "x.mp3 ";
      char tmp_funccall[100];
      FILE *file;
      unsigned long buf1[200000];
     
     if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)

       DieWithError( "socket () failed") ;

      memset(&echoServAddr, 0, sizeof(echoServAddr));       /*  Zero out structure */
      echoServAddr.sin_family = AF_INET;                          /*  Internet addr family */
      echoServAddr.sin_addr.s_addr = inet_addr("127.0.0.1");   /*  Server IP address */
      echoServAddr.sin_port      = htons(9500);     

     ent = readdir(d);
     while(ent)
     {
                x = (strcmp(ent->d_name,"..")) && (strcmp(ent->d_name,"."));
                if(x != 0)
               {
                       strcpy(filePath,filepa);
                       printf("\n%s\n",ent->d_name);
                       strcat(filePath,ent->d_name);
                       printf("\n%s-filepath\n",filePath);

                       file = fopen(filePath,"r");
                          if (file == NULL)
                              {
                              printf("\nno file");
                               }

                              while(!feof(file))
                          {
                              fread(&buf1,60000,1,file);
                             sendto(sock,buf1,60000, 0, (struct sockaddr *)&echoServAddr, sizeof(echoServAddr)) ;
                             fp1 = fopen("x.mp3","wb");                                         
                             fwrite(buf1,60000,1,fp1);
                             strcpy(song,songname);
                              strcpy(tmp_funccall,funcall) ;
                             strcat(tmp_funccall,song);
                             printf("func %s\n",tmp_funccall);
                             system(tmp_funccall);
                             fclose(fp1);
                             }
                   fclose(file);
                }
ent = readdir(d);
       }
       closedir(d);
       close(sock);
       exit(0);
      return 0;
}

void DieWithError(char *errorMessage)
  {
      perror (errorMessage) ;
      exit(1);
 }

I get the following message when mplayer is called , but works fine. Am not getting why I get that message which is highlighted in red.


Code:
func mplayer x.mp3
MPlayer 1.0rc2-4.1.0 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.00GHz (Family: 15, Model: 3, Stepping: 4)
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

Playing x.mp3.
Audio file file format detected.
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
mpg123: Can't rewind stream by 1047 bits!
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
AO: [oss] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:   3.2 (03.2) of 3.0 (03.0)  0.6%

Exiting... (End of file)
func mplayer x.mp3
MPlayer 1.0rc2-4.1.0 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.00GHz (Family: 15, Model: 3, Stepping: 4)
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

Code:
Playing x.mp3.
Audio file file format detected.
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
mpg123: Can't rewind stream by 1563 bits!
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
AO: [oss] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:   3.2 (03.2) of 3.0 (03.0)  0.6%

Exiting... (End of file)


Last edited by vino; 08-25-2008 at 10:30 AM.. Reason: added code tags
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

playing multimedia content under openbsd with Xvid and mplayer

hello. I just installed OpenBSD3.5 and now am using gnome2.4. i've installed mplayer from the openbsd.org packages directory and it seems to work with all kinds of media. The trouble is, it plays all videos too fast. The picture rate is too high and sound is too fast, too. I wonder if anyone... (1 Reply)
Discussion started by: sablot
1 Replies

2. UNIX for Dummies Questions & Answers

sound card and audio song

Hello, How can i install the sound card on solaris 9.00 and also, how can i play MP3 and audio songs on solaris.... pls provide me the complete steps.... thnks (4 Replies)
Discussion started by: taurian1234
4 Replies

3. UNIX for Dummies Questions & Answers

Problem with mplayer

Can someone help with following problem? I'm trying to watch the stream video. mplayer SRTV - Main Air MPlayer SVN-r24130 (C) 2000-2007 MPlayer Team CPU: AMD Sempron(tm) Processor 2800+ (Family: 15, Model: 44, Stepping: 2) CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1... (1 Reply)
Discussion started by: mirusnet
1 Replies

4. What is on Your Mind?

Merry Christmas! & UNIX Song

Merry Christmas to the Greatest UNIX Forum on Earth! This "UNIX Christmas Song" song has been around a while but it's still fun. :-) #UNIX Christmas Song better !pout !cry better watchout lpr why santa claus <north pole >town cat /etc/passwd >list ncheck list ncheck list cat list... (5 Replies)
Discussion started by: cassj
5 Replies

5. Shell Programming and Scripting

mplayer problem

I have this problem using a script that uses mplayer. This is the error messages. INFO: Mplayer Log LOG: MPlayer SVN-r1.0~rc3+svn20090426-4.4.3 (C) 2000-2009 MPlayer Team LOG: mplayer: could not connect to socket LOG: mplayer: No such file or directory LOG: Failed to open LIRC support. You... (1 Reply)
Discussion started by: locoroco
1 Replies

6. BSD

How to play a song in terminal app in os x?

Just wondering -- is there a way to play a song in iTunes from the terminal app? (1 Reply)
Discussion started by: Straitsfan
1 Replies

7. UNIX for Beginners Questions & Answers

Problem compiling Mplayer with file pngdec.c

Hello, I was trying to compile Mplayer 1.3 using gcc 4.4, but I am getting LOTS of error messages when make reaches the pngdec.c file. These are the error messages. libavcodec/pngdec.c:37:18: warning: zlib.h: No such file or directory libavcodec/pngdec.c:82: error: expected... (12 Replies)
Discussion started by: colt
12 Replies
All times are GMT -4. The time now is 08:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy