How to Play Sound and Video Files June 11, 2009 06:27PM | Registered: 15 years ago Posts: 10 |
char characterVariable[20];the same thing as calling
char characterVariable; characterVariable=malloc(20*sizeof(char));I'm a complete noob when it comes to pointers and memory management, so this probably isn't right.
Re: How to Play Sound and Video Files June 11, 2009 06:56PM | Registered: 15 years ago Posts: 703 |
Quote
Nicholas_Roge
I apologize if this has already been posted and replied to (if it has, I couldn't find it), but how would one go about playing .mp3's, .wav's, .avi's, .mov, etc... using homebrew? Also, rather than making a new thread, I have another (rather random) question. Is declaringchar characterVariable[20];the same thing as callingchar characterVariable; characterVariable=malloc(20*sizeof(char));I'm a complete noob when it comes to pointers and memory management, so this probably isn't right.
char characterVariable; characterVariable=malloc(20*sizeof(char));
char* characterVariable; characterVariable = (char*)malloc(20);
Re: How to Play Sound and Video Files June 12, 2009 12:39AM | Registered: 15 years ago Posts: 157 |
Re: How to Play Sound and Video Files June 12, 2009 05:41AM | Registered: 15 years ago Posts: 10 |
Re: How to Play Sound and Video Files June 12, 2009 10:10AM | Registered: 15 years ago Posts: 157 |
-lpng -ljpeg -lz -lwiiuse -lmodplay -lmad -lasnd -lbte -lfat -logc -lm
#--------------------------------------------------------------------------------- # This rule links in binary data with the .mp3 extension #--------------------------------------------------------------------------------- %.mp3.o : %.mp3 #--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o) -include $(DEPENDS) #--------------------------------------------------------------------------------- endif #---------------------------------------------------------------------------------
#include#include #include "song_mp3.h" //yes, the _mp3 is necessary. This file is generated by the compiler.
ASND_Init(); MP3Player_Init();
MP3Player_PlayBuffer (song_mp3, song_mp3_size, NULL); //just type exactly this.
Re: How to Play Sound and Video Files June 12, 2009 03:18PM | Registered: 15 years ago Posts: 10 |
Re: How to Play Sound and Video Files June 12, 2009 03:57PM | Registered: 15 years ago Posts: 157 |
Quote
alainvey
(this is from buffer only, search this subforum for "sound" to find tips of loading from SD/Fat)
Re: How to Play Sound and Video Files June 12, 2009 05:09PM | Registered: 15 years ago Posts: 10 |
Re: How to Play Sound and Video Files June 12, 2009 06:11PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: How to Play Sound and Video Files June 12, 2009 06:14PM | Registered: 16 years ago Posts: 441 |
Re: How to Play Sound and Video Files June 12, 2009 07:06PM | Registered: 15 years ago Posts: 157 |
Re: How to Play Sound and Video Files June 12, 2009 07:31PM | Registered: 15 years ago Posts: 703 |
#include#include #include #include #include #include #include static void *xfb = NULL; static GXRModeObj *rmode = NULL; FILE* the_file = 0; s32 reader_callback(void *fp,void *dat, s32 size) { return fread(dat, size, 1, the_file); } //--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- fatInitDefault(); // Initialise the video system VIDEO_Init(); // This function initialises the attached controllers WPAD_Init(); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu rmode = VIDEO_GetPreferredMode(NULL); // Allocate memory for the display in the uncached region xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // Initialise the console, required for printf console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); // Set up the video registers with the chosen mode VIDEO_Configure(rmode); // Tell the video hardware where our display memory is VIDEO_SetNextFramebuffer(xfb); // Make the display visible VIDEO_SetBlack(FALSE); // Flush the video register changes to the hardware VIDEO_Flush(); // Wait for Video setup to complete VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); ASND_Init(); MP3Player_Init(); MP3Player_Volume(255); the_file = fopen("sd:/apps/test/1.mp3","r"); if (!the_file) exit(0); MP3Player_PlayFile(the_file, reader_callback, 0); bool running = true; while(running) { // Call WPAD_ScanPads each loop, this reads the latest controller states WPAD_ScanPads(); // WPAD_ButtonsDown tells us which buttons were pressed in this loop // this is a "one shot" state which will not fire again until the button has been released u32 pressed = WPAD_ButtonsDown(0); // We return to the launcher application via exit if ( pressed & WPAD_BUTTON_HOME ) running = false; // Wait for the next frame VIDEO_WaitVSync(); } MP3Player_Stop(); fclose(the_file); return 0; }
Re: How to Play Sound and Video Files June 12, 2009 11:16PM | Registered: 15 years ago Posts: 10 |
Re: How to Play Sound and Video Files June 13, 2009 04:32AM | Registered: 16 years ago Posts: 441 |
Re: How to Play Sound and Video Files June 13, 2009 06:03AM | Registered: 15 years ago Posts: 10 |
#include "../../grrlib/GRRLIB/GRRLIB.h" #include <string.h> #include <stdlib.h> #include <stdio.h> #include <wiiuse/wpad.h> #include <dirent.h> #include <fat.h> #include "gfx/console.h" #include "gfx/cursor.h" #include "colors.h" #include "properties.h" #include "additionalFunctions.h" #include "asndlib.h" #include "mp3player.h" //char **artists.name; Mtx GXmodelView2D; ir_t ir; DIR *pdir; struct dirent *pent; struct stat statbuf; int centerTab(tab temp){ return ((temp.width/2)-((strlen(temp.text)*(8*temp.fontSize))/2)); } int centerChar(char temp[], int bGObjectWidth, int fontSize){ return ((bGObjectWidth/2)-(((strlen(temp)*(8*fontSize))/2))); } int centerToScreenH(int widthOfObject){ return (320-(widthOfObject/2)); } int centerToScreenV(int heightOfObject){ return (240-(heightOfObject/2)); } void initializeArtists(){ int index; char dir[40]; pdir=opendir("SD:/MUSIC"); while (((pent=readdir(pdir))!=NULL)&& artists.output<=(20*artists.page)) { if(artists.output==0){ strcpy(artists.name[artists.output],"All"); artists.output++; } if(artists.output==20){ strcpy(artists.name[artists.output],"<-- - or + -->"); break; } stat(pent->d_name,&statbuf); if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0){ continue; }else if(S_ISDIR(statbuf.st_mode)){ if(strlen(pent->d_name)>40){ for(index=0;index<=36;index++){ dir[index]=pent->d_name[index]; } for(;index<=39;index++){ dir[index]='.'; } }else{ strcpy(dir,pent->d_name); } strcpy(artists.name[artists.output],dir); artists.output++; }else if(!(S_ISDIR(statbuf.st_mode))){ continue; } } closedir(pdir); } void drawArtists(int leftMenuX, GRRLIB_texImg tex_console){ int artistTitleHeight=150; int index; /*Selection Box*/ for(index=0,artistTitleHeight=150;index<=20;index++,artistTitleHeight+=10){ if(index==20){ artistTitleHeight+=10; } GRRLIB_Printf(40+leftMenuX,artistTitleHeight, tex_console, black, 1, artists.name[index]); } /*pdir=opendir("SD:/MUSIC"); while ((pent=readdir(pdir))!=NULL) { stat(pent->d_name,&statbuf); if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0){ continue; }else if(S_ISDIR(statbuf.st_mode)){ GRRLIB_Printf(40+leftMenuX,artistTitleHeight, tex_console, black, 1, pent->d_name);//strcpy(artists.name,pent->d_name); }else if(!(S_ISDIR(statbuf.st_mode))){ continue; } artistTitleHeight+=10; } closedir(pdir);*/ } void menuExit(int exitMenuSelection, GRRLIB_texImg tex_console){ GRRLIB_Rectangle(centerToScreenH(500),centerToScreenV(340),500, 340, black, 1); GRRLIB_Rectangle(centerToScreenH(498),centerToScreenV(338),498, 338, grey, 1); GRRLIB_Printf(centerChar("Do you really want to Exit?", 640, 2),100,tex_console,black,2,"Do you really want to Exit?"); GRRLIB_Rectangle(centerToScreenH(72), 127+exitMenuSelection, 72, 32, black, 1); GRRLIB_Rectangle(centerToScreenH(70), 128+exitMenuSelection, 70, 30, white, 1); GRRLIB_Printf(centerChar("YES", 640, 2), 140, tex_console, black, 2, "YES"); GRRLIB_Printf(centerChar("NO", 640, 2), 170, tex_console, black, 2, "NO"); } void mainMenu(){ int i; int leftMenuX=-360; int exitMenuSelection=0; char title[]="Wii Media Player"; char musicDir[]="SD:/MUSIC/"; char other[]="Three Days Grace/One X/Never Too Late.mp3"; char songLocation[1000]; bool leftMenuOpen=false; bool exitMenuVisible=false; u32 buttonDown; u32 buttonHeld; u32 buttonUp; u32 playColor=white; sprintf(songLocation,"%s%s",musicDir,other); filepointer=fopen("SD:/MUSIC/Three Days Grace/One X/Never Too Late.mp3","r"); if(!filepointer){ exit(0); } // Load the text GRRLIB_texImg tex_console = GRRLIB_LoadTexture(console); //Note: Is an 8x8 font GRRLIB_InitTileSet(&tex_console, 8, 8, 0); //Load Cursor GRRLIB_texImg tex_cursor = GRRLIB_LoadTexture(cursor); WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); //MP3Player_PlayBuffer (song_mp3, song_mp3_size, NULL); MP3Player_Volume(255); MP3Player_PlayFile(filepointer,reader_callback,0); ASND_Pause(0); while(1) { WPAD_SetVRes(0, 640, 480); WPAD_ScanPads(); buttonDown = WPAD_ButtonsDown(0); buttonHeld = WPAD_ButtonsHeld(0); buttonUp = WPAD_ButtonsUp(0); WPAD_IR(0, &ir); /*Catch control events*/ if(leftMenuOpen && artists.isActive && (buttonDown && WPAD_BUTTON_DOWN)){ artists.selection+=10; } if(leftMenuOpen && (buttonDown & WPAD_BUTTON_RIGHT)){ if(artists.isActive){ artists.isActive=false; albums.isActive=true; songs.isActive=false; }else if(albums.isActive){ artists.isActive=false; albums.isActive=false; songs.isActive=true; } } if(leftMenuOpen && (buttonDown & WPAD_BUTTON_LEFT)){ if(songs.isActive){ artists.isActive=false; albums.isActive=true; songs.isActive=false; }else if(albums.isActive){ artists.isActive=true; albums.isActive=false; songs.isActive=false; } } if(exitMenuVisible && (buttonDown & WPAD_BUTTON_DOWN)){ exitMenuSelection=30; } if(exitMenuVisible && (buttonDown & WPAD_BUTTON_UP)){ exitMenuSelection=0; } if(exitMenuVisible && (buttonDown & WPAD_BUTTON_A)){ if(exitMenuSelection==0){ break; }else if (exitMenuSelection==30){ exitMenuVisible=false; } } if(!exitMenuVisible && !leftMenuOpen && (buttonHeld & WPAD_BUTTON_A)){ playColor=mediumDarkGrey; } if(!exitMenuVisible && !leftMenuOpen && (buttonUp & WPAD_BUTTON_A)){ playColor=white; if(MP3Player_IsPlaying()){ MP3Player_Stop(); }else if(!MP3Player_IsPlaying()){ } } if(leftMenuOpen && (buttonDown & WPAD_BUTTON_PLUS)){ artists.page++; } if(leftMenuOpen && artists.page!=0 && (buttonDown & WPAD_BUTTON_MINUS)){ artists.page++; } if(buttonDown & WPAD_BUTTON_HOME) { exitMenuVisible=true; } /*--------------------*/ GRRLIB_FillScreen(white); GRRLIB_Printf(centerChar(title, 640, 3), 60, tex_console, black, 3, title); /*Draw the frame*/ GRRLIB_Rectangle(0, 100, 640, 1, black, 0);//Top horizontal bar GRRLIB_Rectangle(leftMenuX+380, 101, 1, 379, black, 0);//Left vertical bar /*--------------*/ GRRLIB_Rectangle(leftMenuX, 102, 380, 378, grey, 1);//Left menu backgrond /*Create the play controls*/ GRRLIB_Rectangle(0, 430, 640, 3, black, 1);//Bottom horizontal bar rectangleWithBorder(centerToScreenH(50),395,50,50,black,2,playColor);//Play button if(!MP3Player_IsPlaying()){ for(i=0;i<20;i+=1){ GRRLIB_Rectangle(310+i,399+i,1,40-(i*2),black, 1); } }else if(MP3Player_IsPlaying()){ GRRLIB_Rectangle(305,403,10,35,black,1); GRRLIB_Rectangle(324,403,10,35,black,1); } /*Start rollover events*/ //To open Left Menu if(ir.sx<=leftMenuX+380&&ir.sy>=100){ leftMenuOpen=true; if(leftMenuX!=0){ leftMenuX+=20; } }else{ leftMenuOpen=false; if(leftMenuX!=-360){ leftMenuX-=20; } } /*---------------------*/ /*Begin outputting tabs*/ //Artists tab if(artists.isActive){ artists.fillColor=grey; }else{ artists.fillColor=mediumDarkGrey; } GRRLIB_Rectangle(leftMenuX+artists.x, artists.y, artists.width, artists.height, artists.borderColor, 0); GRRLIB_Rectangle(leftMenuX+artists.x+1, artists.y+1, artists.width-1, artists.height, artists.fillColor, 1); if(artists.isActive){ GRRLIB_Line(leftMenuX+artists.x, artists.y+artists.height, leftMenuX+artists.x+artists.width, artists.y+artists.height, grey); }else{ GRRLIB_Line(leftMenuX+artists.x, artists.y+artists.height, leftMenuX+artists.x+artists.width, artists.y+artists.height, black); } GRRLIB_Printf(leftMenuX+artists.x+centerTab(artists), artists.y+7, tex_console, black, artists.fontSize, artists.text); //Albums tab if(albums.isActive){ albums.fillColor=grey; }else{ albums.fillColor=mediumDarkGrey; } GRRLIB_Rectangle(leftMenuX+albums.x, albums.y, albums.width, albums.height, albums.borderColor, 0); GRRLIB_Rectangle(leftMenuX+albums.x+1, albums.y+1, albums.width-1, albums.height, albums.fillColor, 1); if(albums.isActive){ GRRLIB_Line(leftMenuX+albums.x, albums.y+albums.height, leftMenuX+albums.x+albums.width, albums.y+albums.height, grey); }else{ GRRLIB_Line(leftMenuX+albums.x, albums.y+albums.height, leftMenuX+albums.x+albums.width, albums.y+albums.height, black); } GRRLIB_Printf(leftMenuX+albums.x+centerTab(albums), albums.y+7, tex_console, black, albums.fontSize, albums.text); //Songs tab if(songs.isActive){ songs.fillColor=grey; }else{ songs.fillColor=mediumDarkGrey; } GRRLIB_Rectangle(leftMenuX+songs.x, songs.y, songs.width, songs.height, songs.borderColor, 0); GRRLIB_Rectangle(leftMenuX+songs.x+1, songs.y+1, songs.width-1, songs.height, songs.fillColor, 1); if(songs.isActive){ GRRLIB_Line(leftMenuX+songs.x, songs.y+songs.height, leftMenuX+songs.x+songs.width, songs.y+songs.height, grey); }else{ GRRLIB_Line(leftMenuX+songs.x, songs.y+songs.height, leftMenuX+songs.x+songs.width, songs.y+songs.height, black); } GRRLIB_Printf(leftMenuX+songs.x+centerTab(songs), songs.y+7, tex_console, black, songs.fontSize, songs.text); /*---------------------*/ /*Begin outputting left menu info*/ if(artists.isActive){ drawArtists(leftMenuX, tex_console); }/*else if(albums.isActive){ drawAlbums(); }else if(songs.isActive){ drawSongs(); }*/ /*---------------------*/ if(exitMenuVisible){ menuExit(exitMenuSelection, tex_console); } GRRLIB_DrawImg(ir.sx, ir.sy, tex_cursor, 0, 1, 1, 0xFFFFFFFF); GRRLIB_Render(); } // Be a good boy, clear the memory allocated by GRRLIB GRRLIB_Exit(); free(tex_console.data); free(tex_cursor.data); MP3Player_Stop(); fclose(filepointer); } int main() { GRRLIB_Init(); WPAD_Init(); fatInitDefault(); ASND_Init(); MP3Player_Init(); setProperties(); initializeArtists(); mainMenu(); exit(0); return 0; }
#--------------------------------------------------------------------------------- # Clear the implicit built in rules #--------------------------------------------------------------------------------- .SUFFIXES: #--------------------------------------------------------------------------------- ifeq ($(strip $(DEVKITPPC)),) $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") endif include $(DEVKITPPC)/wii_rules #--------------------------------------------------------------------------------- # TARGET is the name of the output # BUILD is the directory where object files & intermediate files will be placed # SOURCES is a list of directories containing source code # INCLUDES is a list of directories containing extra header files #--------------------------------------------------------------------------------- GRRLIB := source TARGET := $(notdir $(CURDIR)) BUILD := build SOURCES := source source/gfx $(GRRLIB)/GRRLIB $(GRRLIB)/lib/libpng/pngu DATA := data INCLUDES := #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- CFLAGS = -g -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE) CXXFLAGS = $(CFLAGS) LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- LIBS := -lpng -ljpeg -lz -lwiiuse -lmodplay -lmad -lasnd -lbte -lfat -logc -lm #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- LIBDIRS := #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional # rules for different file extensions #--------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- export OUTPUT := $(CURDIR)/$(TARGET) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ $(foreach dir,$(DATA),$(CURDIR)/$(dir)) export DEPSDIR := $(CURDIR)/$(BUILD) #--------------------------------------------------------------------------------- # automatically build a list of object files for our project #--------------------------------------------------------------------------------- CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C #--------------------------------------------------------------------------------- ifeq ($(strip $(CPPFILES)),) export LD := $(CC) else export LD := $(CXX) endif export OFILES := $(addsuffix .o,$(BINFILES)) \ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ $(sFILES:.s=.o) $(SFILES:.S=.o) #--------------------------------------------------------------------------------- # build a list of include paths #--------------------------------------------------------------------------------- export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I$(CURDIR)/$(BUILD) \ -I$(LIBOGC_INC) #--------------------------------------------------------------------------------- # build a list of library paths #--------------------------------------------------------------------------------- export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ -L$(LIBOGC_LIB) export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean #--------------------------------------------------------------------------------- $(BUILD): @echo cleaning... @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol @echo Building... @[ -d $@ ] || mkdir -p $@ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile #--------------------------------------------------------------------------------- clean: @echo clean ... @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol #--------------------------------------------------------------------------------- run: wiiload $(TARGET).dol #--------------------------------------------------------------------------------- else DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- $(OUTPUT).dol: $(OUTPUT).elf $(OUTPUT).elf: $(OFILES) #--------------------------------------------------------------------------------- # This rule links in binary data with the .jpg extension #--------------------------------------------------------------------------------- %.jpg.o : %.jpg #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- # This rule links in binary data with the .mp3 extension #--------------------------------------------------------------------------------- %.mp3.o : %.mp3 #--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o) -include $(DEPENDS) #--------------------------------------------------------------------------------- endif #---------------------------------------------------------------------------------
Re: How to Play Sound and Video Files June 13, 2009 09:56AM | Registered: 15 years ago Posts: 157 |
Re: How to Play Sound and Video Files June 13, 2009 11:01AM | Registered: 16 years ago Posts: 265 |
Re: How to Play Sound and Video Files June 14, 2009 05:57PM | Registered: 15 years ago Posts: 10 |
Quote
alainvey
Try adding a check for MP3Player_IsPlaying before stopping playback. This is a guess, of course, but I had a similar problem: I've found that if you ask MP3Player to stop when it is not playing, then the program will hang. That, or some other unknown thing fixed my bug.
Quote
henke37
Btw, about video playback, that is one thing that is ok to not use the GX api for, just dump the pixels onto the framebuffer instead.
Re: How to Play Sound and Video Files June 14, 2009 11:15PM | Registered: 16 years ago Posts: 265 |
Re: How to Play Sound and Video Files June 17, 2009 10:13PM | Registered: 15 years ago Posts: 10 |