学习笔记(1)——粤嵌gec6818实现电子相册,音乐播放器,视频播放器。

项目要求:

(1)设计一个初始界面,并且设置电子相册,音乐播放器,视频播放器三个触摸按键。

(2)电子相册——能够实现相册的幻灯片功能,实现相册左右滑动切换相片。

(3)音乐播放器实现——切歌,播放和暂停功能。

(4)视频播放器实现——播放、暂停、音量大小、快进倒退等功能。

(5)对代码进行集成化

项目设计:

(1)头文件、设置变量和素材引入

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <linux/input.h>
#include <pthread.h>
#include <stdlib.h>

int get_touch(int *th_x,int *th_y);//x轴和y轴的位置。
int show_color(int color,int x,int y,int w,int h);//颜色的显示x和y设定位置,w和h设定显示大小
int mmap_bmp(char *namebuf,int x,int y,int w,int h);//

int lcd,touch;
int *map;

int th_x,th_y,th_falg = 0,falg_2 = 0,i = -1;
pthread_t pid;

int fd_fifo;

char music_path[4][32] = {"faded.mp3","faded1.mp3","faded2.mp3"};

char name_buf[4][20] = {"01.bmp","02.bmp","1.bmp"};

(2)对设备的初始化和停止

int __INIT__()
{
    touch = open("/dev/input/event0",O_RDWR);
    if(touch == -1)
    {
        perror("open touch failed");
        return -1;
    }
    lcd = open("/dev/fb0",O_RDWR);
    if(lcd == -1)
	{
		perror("open lcd failed");
		return -1;
	}
    map = (int *)mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED,lcd,0);
	if(map == MAP_FAILED)
	{
		perror("mmap failed");
		return -1;
	}


    if(access("/fifo",F_OK))// 默认管道文件创建在根目录  F_OK:判断是否存在
	{
		//如果没有创建
		mkfifo("/fifo",777); //创建管道文件函数

	}
	fd_fifo = open("/fifo",O_RDWR);
	if(fd_fifo == -1)
	{
		printf("创建管道文件失败!\n");
		return -1;

	}
	return 0;
}

int __FrEe()
{
    close(touch);
    close(lcd);
    munmap(map,800*400*4);
    system("killall -9 mplayer");
}

int Send_Cmd(char *cmd)//写入管道文件
{
	write(fd_fifo,cmd,strlen(cmd));
	
	return 0;
}

(3)限制图片的显示大小


void *cyc_showbmp(void *arg)
{
    for(int i = 0;i<3;i++)
    {
        mmap_bmp(name_buf[i],0,0,800,400);
        sleep(3);
        if(i == 2) i=-1;
    }
}

(4)获取坐标

//获取坐标
int get_touch(int *th_x,int *th_y)
{
    int old_x,old_y;
    struct input_event buf;
    while(1)
    {
        read(touch,&buf,sizeof(buf));

        if(buf.type == EV_ABS && buf.code == ABS_X)
            *th_x = buf.value;
        if(buf.type == EV_ABS && buf.code == ABS_Y)
            *th_y = buf.value;

        if(buf.type == EV_KEY && buf.code == BTN_TOUCH && buf.value == 1)
        {
            old_x = *th_x;
            old_y = *th_y;
        }
        
        if(buf.type == EV_KEY && buf.code == BTN_TOUCH && buf.value == 0)
        {
            if(old_x < *th_x && (*th_x - old_x >= 50)) return 1;//向右移动
            if(old_x > *th_x && (old_x - *th_x >= 50)) return 2;//向左移动
            break;
        }

    }

    return 0;
}

(5)颜色的显示

int show_color(int color,int x,int y,int w,int h)
{
    int * new_map = map + (800*y) + x;
	
	for(int i = 0 ;i < h;i++)
	{
		for(int j = 0;j < w;j++)
		{
			*(new_map+(i*800+j)) = color;//buf[((h -1 -i)*w)+j];
		}
	}
    return 0;
}

(6)在任意位置显示图片

//任意位置,任意大小刷图
int mmap_bmp(char *namebuf,int x,int y,int w,int h)
{
    int bmp = open(namebuf,O_RDWR);
    if(bmp == -1)
    {
        perror("open failed");
        return -1;
    }

	char buf[w*h*3];
	int new_buf[w*h];
	
	lseek(bmp,54,SEEK_SET);
	
	read(bmp,buf,w*h*3);
	
	for(int i = 0 ;i < h;i++)
	{
		for(int j = 0;j < w;j++)
		{
			new_buf[(i*w)+j] = buf[3*((i*w)+j)] << 0 | buf[3*((i*w)+j)+1] << 8 | buf[3*((i*w)+j)+2] << 16;
		}
	}
	
	int * new_map = map + (800*y) + x;
	
	for(int i = 0 ;i < h;i++)
	{
		for(int j = 0;j < w;j++)
		{
			*(new_map+(i*800+j)) = new_buf[((h -1 -i)*w)+j];
		}
	}
	close(bmp);
	return 0;
}

(7)电子相册

int pic()
{
    while(1)
    {  
        //获取坐标
        
        //判断坐标位置
                        mmap_bmp("12.bmp",0,400,800,80);
                    get_touch(&th_x,&th_y);
                    if(th_x >= 0 && th_x < 200 && th_y >= 400 &&th_y <= 480)
                    {
                        //结束自动循环
                        
                            pthread_cancel(pid);
                            falg_2 = 0;
                            mmap_bmp(name_buf[i],0,0,800,400);
                            
                    }
                    if(th_x >= 201 && th_x < 400 && th_y >= 400 &&th_y <= 480)
                    {
                        //开启自动循环
                        
                        pthread_create(&pid,NULL,cyc_showbmp,NULL);
                    }
                    if(th_x >= 401 && th_x < 600 && th_y >= 400 &&th_y <= 480)
                    {
                        //上一张 数组 --
                        i--;
                        if(i < 0) i = 3;
                        mmap_bmp(name_buf[i],0,0,800,400);
                    }//上一张
                    if(th_x >= 601 && th_x < 799 && th_y >= 400 &&th_y <= 480)
                    {
                        //下一张 数组 ++
                        i++;
                        if(i > 3) i = 0;
                        printf("1111\n");
                        mmap_bmp(name_buf[i],0,0,800,400);
                    } //下一张
                   if(th_x >= 0 && th_x < 100 && th_y >= 0 &&th_y <= 100)
                    break;
                         
             //启动自动循环:开启线程
            
            //停止自动循环:结束线程
            
            //退出
                
 }
}

(8)音乐播放器

int music()
{
    //execl("/bin/madplay", "madplay", music_path[i], NULL);
    

    system("madplay faded.mp3 &");
    sleep(1);
    while(1)
    {
        //获取坐标
        mmap_bmp("14.bmp",0,0,800,400);
        mmap_bmp("16.bmp",0,400,800,80);
        get_touch(&th_x,&th_y);
        //判断坐标位置
        /*if(th_x >= 441 && th_x <= 560 && th_y >= 400 && th_y <= 480)//结束
        {
            system("killall -9 madplay");
        }*/
        if(th_x >= 0 && th_x < 200 && th_y >= 400 &&th_y <= 480)//暂停
        {
            printf("继续!\n");
            system("killall  -18 madplay");
		    //Send_Cmd("pause\n");
        }
         if(th_x >= 201 && th_x < 400 && th_y >= 400 &&th_y <= 480)
        {
                        -
         i--;
        if(i < 0) i = 3;
        system(name_buf[i]);
        }//
        if(th_x >= 401 && th_x < 600 && th_y >= 400 &&th_y <= 480)
        { 
        i++;
        if(i > 3) i = 0;
        system( name_buf[i] );
        } //下一首
        if(th_x >= 551 && th_x <= 800 && th_y >= 400 && th_y <= 480)//退出
        {
            system("killall -19 madplay");
            break;
        }
        if(th_x >= 0 && th_x < 100 && th_y >= 0 &&th_y <= 100)
        {
          system("killall -9 madplay");
            break;
        }
                    
    }
}

(9)视频播放器

int video()
{
    system("mplayer -slave -quiet -input file=/fifo -geometry 0:0 -zoom -x 800 -y 400 Faded3.avi &");
	sleep(1);
            mmap_bmp("13.bmp",0,0,800,480);
    while(1)
    {
        //获取坐标
        /*show_color(0x00ffff00,0,400,120,80);
        show_color(0x00ff0000,120,400,120,80);
        show_color(0x0000ff00,240,400,200,80);
        show_color(0x000000ff,440,400,120,80);
        show_color(0x00ff00ff,560,400,120,80);
        show_color(0x00ffffff,680,400,119,80);*/

        get_touch(&th_x,&th_y);
        //判断坐标位置
        if(th_x>241 && th_x<440 && th_y>400 && th_y<480)
        {
            printf("暂停 继续!\n");
		    Send_Cmd("pause\n");
        }
		if(th_x>0 && th_x<120 && th_y>400 && th_y<480)
		{
		    printf("音量+\n");
		    Send_Cmd("volume +10\n");
		}
		if(th_x>121 && th_x<240 && th_y>400 && th_y<480)
		{
		    printf("音量-\n");
		    Send_Cmd("volume -10\n");
		}
		if(th_x>441 && th_x<560 && th_y>400 && th_y<480)
		{
			printf("快进!\n");
			Send_Cmd("seek +10\n");
		}
		if(th_x>561 && th_x<680 && th_y>400 && th_y<480)
		{
			printf("快退!\n");
			Send_Cmd("seek -10\n");
		}
		if(th_x>681 && th_x<799 && th_y>400 && th_y<480)
        {
            system("killall -9 mplayer");
            break;
        }
        
			
            //启动视频播放器
            //退出
            //上一个
            //下一个
            //暂停
            //继续
            //音量+-
            //快进快退
        
    }
}

(10)主函数

int main(int argc, char const *argv[])
{
    //初始化
    int ret = __INIT__();
    if(ret == -1) return -1;

    
    while(1)
    {//主界面
    mmap_bmp("11.bmp",0,0,800,480);
        //获取坐标
    get_touch(&th_x,&th_y);
        //判断坐标位置
        if(th_x >= 100 && th_x < 200 && th_y >= 300 && th_y < 400)
        {
            //图片
            pic();
        }

        if(th_x >= 300 && th_x < 500 && th_y >= 300 && th_y < 400)
        {
            //音乐
            music();
        }

        if(th_x >= 600 && th_x < 700 && th_y >= 300 && th_y < 400)
        {
            //视频
          video();
        } 
        
    }

    
    //结束初始化
    __FrEe();
    return 0;
}

 

 (11)项目成果

 

 

(12)程序编译指令  arm-linux-gcc xxx.c -o xxx -lphread 

 

 

 

 

  • 71
    点赞
  • 503
    收藏
    觉得还不错? 一键收藏
  • 27
    评论
粤嵌gec6818开发板可以用来制作音乐播放器。作为一块高性能的开发板,它具备强大的处理能力和丰富的接口资源,是一款理想的音乐播放器开发平台。 首先,gec6818开发板搭载了强大的八核ARM Cortex-A53处理器和高性能的Mali-T860 GPU,能够提供稳定流畅的音频播放和界面操作。其它核心配置,如4GB内存和64GB闪存,也能保证音乐播放的顺畅性和存储容量。 其次,gec6818开发板拥有丰富的接口资源,包括USB、HDMI、以太网、SD卡等,可以连接到各种外部设备,如音箱、耳机、显示器等。可以通过USB接口连接外部存储器,将音乐文件存储在U盘或移动硬盘中,方便传输和播放。 此外,gec6818开发板还支持多种音频格式和编码方式,如MP3、WAV、FLAC等,同时通过Linux操作系统的支持,可以实现强大的音频处理和控制功能,如均衡器调节、音量控制、音频格式转换等。 最后,开发者可以使用gec6818开发板上的硬件接口和软件开发工具,进行自定义的应用开发。借助开源的Linux系统和丰富的软件资源,可以实现自定义的UI界面和功能。同时,gec6818开发板还支持外接触摸屏,用户可以通过触摸屏进行音乐播放器的操作,提升用户体验。 综上所述,粤嵌gec6818开发板具备强大的处理能力和丰富的接口资源,可以用来制作高性能的音乐播放器,并提供多种功能和自定义选项,非常适合音乐爱好者和开发者使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 27
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值