聚丰项目 > 即时播放视频

即时播放视频

即时播放视频,主要是用于通过WiFi传输音频和视频文件到设备中即时播放,并不受限于音频,视频文件的大小。也不需要设备有很大的一个存储空间。采用边播边放边删的一个方式,在设备中每次只存储一部分要播放的文件,播过的文件即时删掉,因此只需一个很小的存储空间就可以播放一个很大的音频视频文件。

diney_db4 diney_db4

分享
0 喜欢这个项目
团队介绍

diney_db4 diney_db4

团队成员

张文雄 程序员

分享
项目简介
即时播放视频,主要是用于通过WiFi传输音频和视频文件到设备中即时播放,并不受限于音频,视频文件的大小。也不需要设备有很大的一个存储空间。采用边播边放边删的一个方式,在设备中每次只存储一部分要播放的文件,播过的文件即时删掉,因此只需一个很小的存储空间就可以播放一个很大的音频视频文件。
硬件说明

开发板:NUCLEO-64 STM32F401

主控MCU:STM32F401RET6

image.png

WIFI模块:3080B

image.png  

音频解码模块:VS1053

image.png 

 

液晶显示:TFTLCD液晶屏

image.png

软件说明


下位机即时播放音频,视频部分代码。


void mp3_play(void)

{

         u8 res;

        DIR mp3dir;                      //Ŀ¼

         FILINFO mp3fileinfo;//ÎļþÐÅÏ¢

         u8 *fn;                              //³¤ÎļþÃû

         u8 *pname;                        //´ø·¾¶µÄÎļþÃû

         u16 totmp3num;              //ÒôÀÖÎļþ×ÜÊý

         u16 curindex;            //ͼƬµ±Ç°Ë÷Òý

         u8 key;                                 //¼üÖµ               

        u16 temp;

         u16 *mp3indextbl;  //ÒôÀÖË÷Òý±í

        while(f_opendir(&mp3dir,"0:/MUSIC"))//´ò¿ªÍ¼Æ¬Îļþ¼Ð

        {           

                   Show_Str(30,190,240,16,"MUSICÎļþ¼Ð´íÎó!",16,0);

                   delay_ms(200);                                     

                   LCD_Fill(30,190,240,206,WHITE);//Çå³ýÏÔʾ             

                   delay_ms(200);                                     

         }                                                                                   

         totmp3num=mp3_get_tnum("0:/MUSIC"); //µÃµ½×ÜÓÐЧÎļþÊý

       while(totmp3num==NULL)//ÒôÀÖÎļþ×ÜÊýΪ0             

        {           

                   Show_Str(30,190,240,16,"ûÓÐÒôÀÖÎļþ!",16,0);

                   delay_ms(200);                                     

                   LCD_Fill(30,190,240,146,WHITE);//Çå³ýÏÔʾ             

                   delay_ms(200);                                     

         }                                                                                              

       mp3fileinfo.lfsize=_MAX_LFN*2+1;                                                        //³¤ÎļþÃû×î´ó³¤¶È

         mp3fileinfo.lfname=mymalloc(SRAMIN,mp3fileinfo.lfsize);   //Ϊ³¤Îļþ»º´æÇø·ÖÅäÄÚ´æ

        pname=mymalloc(SRAMIN,mp3fileinfo.lfsize);                                   //Ϊ´ø·¾¶µÄÎļþÃû·ÖÅäÄÚ´æ

        mp3indextbl=mymalloc(SRAMIN,2*totmp3num);                             //ÉêÇë2*totmp3num¸ö×Ö½ÚµÄÄÚ´æ,ÓÃÓÚ´æ·ÅÒôÀÖÎļþË÷Òý

        while(mp3fileinfo.lfname==NULL||pname==NULL||mp3indextbl==NULL)//ÄÚ´æ·ÖÅä³ö´í

        {           

                   Show_Str(30,190,240,16,"ÄÚ´æ·ÖÅäʧ°Ü!",16,0);

                   delay_ms(200);                                     

                   LCD_Fill(30,190,240,146,WHITE);//Çå³ýÏÔʾ             

                   delay_ms(200);                                     

         }    

         VS_HD_Reset();

         VS_Soft_Reset();

         vsset.mvol=220;                                                     //ĬÈÏÉèÖÃÒôÁ¿Îª220.

         mp3_vol_show((vsset.mvol-100)/5);       //ÒôÁ¿ÏÞÖÆÔÚ:100~250,ÏÔʾµÄʱºò,°´ÕÕ¹«Ê½(vol-100)/5,ÏÔʾ,Ò²¾ÍÊÇ0~30  

         //¼Ç¼Ë÷Òý

    res=f_opendir(&mp3dir,"0:/MUSIC"); //´ò¿ªÄ¿Â¼

         if(res==FR_OK)

         {

                   curindex=0;//µ±Ç°Ë÷ÒýΪ0

                   while(1)//È«²¿²éѯһ±é

                   {

                            temp=mp3dir.index;                                                                          //¼Ç¼µ±Ç°index

                 res=f_readdir(&mp3dir,&mp3fileinfo);                      //¶ÁȡĿ¼ÏµÄÒ»¸öÎļþ

                 if(res!=FR_OK||mp3fileinfo.fname[0]==0)break;    //´íÎóÁË/µ½Ä©Î²ÁË,Í˳ö            

                     fn=(u8*)(*mp3fileinfo.lfname?mp3fileinfo.lfname:mp3fileinfo.fname);                             

                            res=f_typetell(fn);  

                            if((res&0XF0)==0X40)//È¡¸ßËÄλ,¿´¿´ÊDz»ÊÇÒôÀÖÎļþ        

                            {

                                     mp3indextbl[curindex]=temp;//¼Ç¼Ë÷Òý

                                     curindex++;

                            }           

                   }

         }  

     curindex=0;                                                                                                   //´Ó0¿ªÊ¼ÏÔʾ

     res=f_opendir(&mp3dir,(const TCHAR*)"0:/MUSIC");           //´ò¿ªÄ¿Â¼

         while(res==FR_OK)//´ò¿ª³É¹¦

         {       

                   dir_sdi(&mp3dir,mp3indextbl[curindex]);                          //¸Ä±äµ±Ç°Ä¿Â¼Ë÷Òý        

        res=f_readdir(&mp3dir,&mp3fileinfo);                      //¶ÁȡĿ¼ÏµÄÒ»¸öÎļþ

        if(res!=FR_OK||mp3fileinfo.fname[0]==0)break;    //´íÎóÁË/µ½Ä©Î²ÁË,Í˳ö

            fn=(u8*)(*mp3fileinfo.lfname?mp3fileinfo.lfname:mp3fileinfo.fname);                             

                   strcpy((char*)pname,"0:/MUSIC/");                                   //¸´ÖÆ·¾¶(Ŀ¼)

                   strcat((char*)pname,(const char*)fn);                             //½«ÎļþÃû½ÓÔÚºóÃæ

                 LCD_Fill(30,190,240,190+16,WHITE);                                 //Çå³ý֮ǰµÄÏÔʾ

                   Show_Str(30,190,240-30,16,fn,16,0);                                 //ÏÔʾ¸èÇúÃû×Ö

                   mp3_index_show(curindex+1,totmp3num);

                   key=mp3_play_song(pname);                                                      //²¥·ÅÕâ¸öMP3   

                   if(key==2)                   //ÉÏÒ»Çú

                   {

                            if(curindex)curindex--;

                            else curindex=totmp3num-1;

                 }else if(key<=1)//ÏÂÒ»Çú

                   {

                            curindex++;                   

                            if(curindex>=totmp3num)curindex=0;//µ½Ä©Î²µÄʱºò,×Ô¶¯´ÓÍ·¿ªÊ¼

                 }else break;      //²úÉúÁË´íÎó     

         }                                                                                                      

         myfree(SRAMIN,mp3fileinfo.lfname);     //ÊÍ·ÅÄÚ´æ                            

         myfree(SRAMIN,pname);                                     //ÊÍ·ÅÄÚ´æ                            

         myfree(SRAMIN,mp3indextbl);                          //ÊÍ·ÅÄÚ´æ       

}

 

unsigned char PlayMusicStreamFunction(unsigned char *dataBuffer, unsigned short lenght)

{

    PlayMusicStream = 4;

    if(MusicStreamDataCount>100)

    {

        PlayMusicEnFlag = 1;

        MusicStreamDataRecciveCount++;

    }

    //#if  PRINTF_DEBUG == 1  

//printf(" ???? MusicStreamDataCount %d , Mp3FlieSizeCount %d  ?? %d \r\n",MusicStreamDataCount, Mp3FlieSizeCount,GetSystick1ms());

    ///#endif

    

    

    if(PLAY_MUSIC_LENGHT - MusicStreamDataCount >= lenght)

    {

        memcpy(PlayMusicData+MusicStreamDataCount,dataBuffer,lenght);

        MusicStreamDataCount += lenght;

    }

    else

    {

        MusicStreamDataCount = 0;

        memcpy(PlayMusicData+MusicStreamDataCount,dataBuffer,lenght);

        MusicStreamDataCount += lenght;

        PlayMusicFlay = 1;

    }


    if(Mp3FlieSizeCount > MusicStreamDataCount) 

    {

        if((Mp3FlieSizeCount - MusicStreamDataCount) < 4*1024)

    return 0;

    }

    else if(PlayMusicFlay)

    {

        if((MusicStreamDataCount - Mp3FlieSizeCount) < 4*1024)

    return 0;

    }

    

    return 1;

    

}


void SystemProcessPlayMusic(void)

{

    //static unsigned int size = 0;

    unsigned int lenght = 0;

    

    if(PlayMusicEnFlag)

    {

        if(StartGetMusicData)

        {

            StartGetMusicData = 0;

           if(PlayMusicStream>3)

            {

                if(Mp3FlieSizeCount < PLAY_MUSIC_LENGHT)

                {

                    if(MusicStreamDataRecciveCount)

                    {

                        MusicStreamDataRecciveCount--;

                    }

                    if(StopPlayRobotMusic)

                    {

                        StopPlayRobotMusic = 0;

                        Mp3FlieSizeCount = 0;

                        PlayMusicEnFlag = 0;

                        //StopSkillPlay();

                        //memset(Mp3FileName,0,50);

                        //memset(PlayMusicData,0,1024);

                        //f_close(&Mp3_fnew);

                        #if  PRINTF_DEBUG == 1  

                printf("StopPlayRobotMusic   Í£Ö¹²¥·Å \r\n");

                        #endif

                        return;

                    }

                    lenght = 1024;

                    //#if  PRINTF_DEBUG_fatfs == 1 

                    //printf(" ÕýÔÚ²¥·Å ±ß²¥±ß·Å MusicStreamDataCount %d £¬ Mp3FlieSizeCount %d  ʱ¼ä %d \r\n",MusicStreamDataCount, Mp3FlieSizeCount,GetSystick1ms());

                   

                    //#endif

                    System.Device.Music.PlayMp3File(PlayMusicData+Mp3FlieSizeCount,lenght);

                    Mp3FlieSizeCount += lenght;

                    if(Mp3FlieSizeCount == MusicStreamDataCount)

                    {

                        PlayMusicStream = 1;

                        Mp3FlieSizeCount = 0;

                        MusicStreamDataCount = 0;

                        PlayMusicFlay = 0;

                    }

                    if(Mp3FlieSizeCount >= PLAY_MUSIC_LENGHT)

                    {

                        Mp3FlieSizeCount = 0;

                    }

                }

            }

            else if(PlayMusicStream == 0)

            { 

               if(Mp3FlieSizeCount < Mp3_fnew.fsize)

               {

                   f_lseek(&Mp3_fnew, Mp3FlieSizeCount);

                   lenght = Mp3_fnew.fsize - Mp3FlieSizeCount;

                   if(lenght > MAX_BYTECOUNT)

                       lenght = MAX_BYTECOUNT;

                   

                   Mp3_res_sd = f_read(&Mp3_fnew, PlayMusicData, lenght, &Mp3_fnum);

                   if(Mp3_res_sd == FR_OK)

                   {

                       

                       play_music((unsigned char*)(&PlayMusicData[0]),lenght);

                       Mp3FlieSizeCount += lenght;

                       if(Mp3FlieSizeCount >= Mp3_fnew.fsize)

                       {

                           Mp3FlieSizeCount = 0;

                           PlayMusicEnFlag = 0;

                           f_close(&Mp3_fnew);

                       }

                   }

                   else

                   {

                       Mp3FlieSizeCount = 0;

                       PlayMusicEnFlag = 0;

                       f_close(&Mp3_fnew);

                   }

                   #if  PRINTF_DEBUG == 1  

                   printf("²¥·Åmp3Îļþ count %ld \r\n",Mp3FlieSizeCount);

                   #endif

               }

               else

               {

                   Mp3FlieSizeCount = 0;

                   PlayMusicEnFlag = 0;

                   f_close(&Mp3_fnew);

               }

            }

        }

    }

}


演示效果

image.png

评论区(0 )